无法解析"java.sql.SQLException:[Microsoft] [ODBC SQL Server驱动程序]无效的描述符索引";错误 [英] unable to resolve "java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index" error
本文介绍了无法解析"java.sql.SQLException:[Microsoft] [ODBC SQL Server驱动程序]无效的描述符索引";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是尝试从表中获取密码的jsp代码
here is the jsp code which tries to fetch password from a table
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dsn2");
String U=(String)session.getAttribute("uname");
String query="select pwd from img_pwd where uname='"+U+"'";
Statement s=con.createStatement();
ResultSet r= s.executeQuery(query);
String pas="";
if(r.next())
{
pas=r.getString(2);
}
con.close();
数据库中的表"img_pwd"像这样-
and the table "img_pwd" in the database goes like this--
- (uname,nvarchar(50)
- (pwd,nvarchar(20))
因此,如问题标题中所述,我得到错误- java.sql.SQLException:[Microsoft] [ODBC SQL Server驱动程序]无效的描述符索引
Hence as described in the question title, i get the error--java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Invalid Descriptor Index
注意::我已经知道结果集代码存在问题,但是我无法弄清楚.
NOTE: i have come to know that there is a problem with my resultset code but i am unable to figure it out.
有人可以引导我吗??? 谢谢.
Can anybody Guide me??? Thanks.
推荐答案
您的SQL正在选择一个字段:
Your SQL is selecting one field:
String query="select pwd from img_pwd where uname='"+U+"'";
但是此行正在查找字段#2(并且您仅选择一个字段).
But this line is looking for field #2 (and you're only SELECTing one).
pas=r.getString(2);
将其更改为此:
pas=r.getString(1);
查看全文