column xx not found??

petit 2003-08-19 01:16:16
使用jdbc连接数据库
statement,ResultSet都是正确的
。。。。。
rs = stmt.executeQuery(sql);
if (rs.next())
{
String pwdInDB = (String)rs.getObject(0);
if (pwdInDB.equals(pwd))
{
loginFlag = true;
}
}
。。。。。
为什么抛出异常column xx not found??
...全文
869 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
petit 2003-08-19
  • 打赏
  • 举报
回复
字段名也试过了
hfayga 2003-08-19
  • 打赏
  • 举报
回复
rs.getObject()跟字段名试试
hesi726 2003-08-19
  • 打赏
  • 举报
回复
column xx not found:
SQL错掉了!
rs = stmt.executeQuery(sql);就已经抛出了异常!
relive 2003-08-19
  • 打赏
  • 举报
回复
应该是SQL拼错了

比如 select aa from TableA;

可是 TableA 里根本没有 aa 这个列
petit 2003-08-19
  • 打赏
  • 举报
回复
你是指数据库连接问题还是数据库中表的问题?
我在数据库中查找表是没问题的呀
cshchina 2003-08-19
  • 打赏
  • 举报
回复
rs.getString(1);

不过既然你的异常是column XX not found,那肯定是你的数据库有问题
petit 2003-08-19
  • 打赏
  • 举报
回复
我有3个字段,但是无论是1,还是2、3都不行
pcdll 2003-08-19
  • 打赏
  • 举报
回复
是从1为起始的,即(String)rs.getObject(1);
petit 2003-08-19
  • 打赏
  • 举报
回复
出错信息是:
select pwd from login
yes
yes
hi
in
java.sql.SQLException: column pwd not found
at SQLite.JDBC2x.JDBCResultSetMetaData.findColByName(JDBCResultSetMetaData.java:189)
at SQLite.JDBC2x.JDBCResultSet.findColumn(JDBCResultSet.java:52)
at SQLite.JDBC2x.JDBCResultSet.getInt(JDBCResultSet.java:138)
at CheckLogin.isLogin(CheckLogin.java:52)
at CheckLogin.main(CheckLogin.java:78)
petit 2003-08-19
  • 打赏
  • 举报
回复
基类:
/*
* Created on 2003-8-18
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
import java.sql.*;
import SQLite.JDBC2x.*;
public class SQLiteBase
{
public final String drivers = "SQLite.JDBCDriver";
public final String url = "jdbc:sqlite:/phonedb.db";

public JDBCConnection conn = null;
public JDBCStatement stmt1 = null;
public JDBCStatement getStatement()
{
try
{
Driver driver = (Driver)Class.forName(drivers).newInstance();
DriverManager.registerDriver(driver);
conn = (JDBCConnection)DriverManager.getConnection(url);
stmt1 = (JDBCStatement)conn.createStatement();
}
catch (Exception e)
{
e.printStackTrace();
}
System.out.println("yes");
return stmt1;

}
public static void main(String[] args)
{
}
}


子类:
import java.sql.*;
//import SQLite.JDBC2x.*;
//import SQLite.*;
import SQLite.JDBC2x.JDBCResultSet;
import SQLite.JDBC2x.JDBCStatement;
public class CheckLogin extends SQLiteBase
{
private String user = "";
private String pwd = "";
JDBCStatement stmt = null;
boolean loginFlag = false;
public String sql = "";
JDBCResultSet rs;
public void setUser(String user)
{
this.user = user;
}
public void setPwd(String pwd)
{
this.pwd = pwd;
}
public void createSql()
{
sql = "select pwd from login ";

System.out.println(sql);
}
public boolean isLogin()
{
try
{
stmt = getStatement();
rs = (JDBCResultSet)stmt.executeQuery(sql);
System.out.println("hi");
if (rs != null)
{
while (rs.next())
{
System.out.println("in");
int pwdInDB = rs.getInt("pwd");
//System.out.println(pwdInDB);
//if (pwdInDB.equals(pwd))
//{
// loginFlag = true;
//}
}
}else
{
System.out.println("not search");
}
}
catch (java.lang.Exception e)
{
e.printStackTrace();
}
finally
{
return loginFlag;
}
}
public static void main(String[] args)
{
CheckLogin l = new CheckLogin();
l.createSql();
l.getStatement();
l.isLogin();
}
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧