我一直在尝试创建一个登录页面,并且从包含用户凭据的数据库中提取信息时遇到了问题。运行代码时,我收到以下错误"错误:DB2 SQL错误:SQLCODE = -206,SQLSTATE = 42703,SQLERRMC = USERNAME,DRIVER = 3.68.61"意思是(我认为)无法找到列用户名,但它就在那里。表USERS包含用户名,密码,f_name和l_name列。此应用程序的用户名和密码通过JSP收集并传递给servlet,而servlet又调用以下.java,它已经传递了用户输入的用户名和密码:
public class Database {
public String lookup( String username, String password) throws SQLException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultset = null;
String f_name = "";
String query = "SELECT f_name FROM USERS WHERE username = ? AND password = ?";
try
{
System.out.println("Connecting to Database");
Class.forName("com.ibm.db2.jcc.DB2Driver");
connection = DriverManager.getConnection("jdbc:db2://ipaddress:port/database name", "username", "userpassword");
System.out.println("Connection Successful");
statement = connection.prepareStatement(query);
statement.setString(1, username);
statement.setString(2, password);
resultset = statement.executeQuery();
if( resultset.next())
{
f_name = resultset.getString("f_name");
}
}
catch(ClassNotFoundException error)
{
System.out.println("Error: " + error.getMessage());
}
catch ( SQLException error)
{
System.out.println("Error: " + error.getMessage());
}
finally
{
if( connection != null)
{
connection.close();
}
if( statement != null)
{
statement.close();
}
if( resultset != null)
{
resultset.close();
}
}//end finally
return f_name;
}
}
有关正在发生的事情的任何想法?
答案 0 :(得分:1)
42703 表示检测到未定义的列,属性或参数名称。
以下是包含不同DB2错误代码https://urssanj00.wordpress.com/2008/03/04/db2-sql-error-code-and-description/
的链接答案 1 :(得分:0)
那可能是你用小写创建了你的列吗?试试select colname from syscat.columns where tabname = 'USERS'
。如果列以小写字母显示,则必须在每个查询中引用它们:select "f_name" from users where "username" = 'whatever'
。