如何获得int(identity)类型字段的值(在线等候) 应该不是你说的问题!!是其他问题引起的!!你把源代码贴出来看看或者你先试试getObject("id")然后再转成你想要的类型 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 谢谢你看我的贴子,代码如下:<%try{ String url=new String(); String SQL=new String(); url="jdbc:odbc:geography"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection(url,"sa",""); SQL="select * from article"; Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(SQL); while(rs.next()){ String count=new String(rs.getString("count"));//这个int类型的可以 out.println(count); String id=new String(rs.getString("id"));//这个int(identity)类型的出错 out.println(id); } rs.close(); con.close();}catch(SQLException ex){ while(ex!=null){ out.println("SQLState:"+ex.getSQLState()); out.println("Message:"+ex.getMessage()); out.println("Vendor:"+ex.getErrorCode()); ex=ex.getNextException(); }}%> 你的数据库中有没有ID这个字段?如果有把:Statement stmt=con.createStatement();改为Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.TYPE_CONCUR_READ_ONLY);试试 这样吧。你看你的ID在geography表中是第几个字段,如果是第1个的话。用这个试试,String id=new String(rs.getString(1));是第2个的话就是:String id=new String(rs.getString(2));试试吧。怪了。 那就试试这个:<%try{ String url=new String(); String SQL=new String(); url="jdbc:odbc:geography"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection(url,"sa",""); SQL="select * from article"; Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.TYPE_CONCUR_READ_ONLY); ResultSet rs=stmt.executeQuery(SQL); ResultSetMetaData rsmd = rs.getMetaData(); int cols = rsmd.getColumnCount(); for (int i=1;i<=cols;i++) out.print(rsmd.getColumnName(i)+"|"); out.print("<br>"); while(rs.next()){ for (int i=1;i<=cols;i++) out.print(new String(rs.getObject(i))+"|") ; out.print("<br>"); //String count=new String(rs.getString("count"));//这个int类型的可以 //out.println(count); //String id=new String(rs.getString("id"));//这个int(identity)类型的出错 //out.println(id); } rs.close(); con.close();}catch(SQLException ex){ while(ex!=null){ out.println("SQLState:"+ex.getSQLState()); out.println("Message:"+ex.getMessage()); out.println("Vendor:"+ex.getErrorCode()); ex=ex.getNextException(); }}%> 非常感谢Andrawu和虚竹和尚,我的问题解决了。我将SQL="select * from article";改为:SQL="select count,id from article";就行了。看来取值是有顺序的。 对,这是个老问题了,从MS SQLServer中取数据必须要按照顺序,否则就会报“无效的描述符索引”错误。MS SQLServer is rubbish。 Tomcat5.5服务器问题!急! 在帮我看看我下的那错了谢谢了 谁能帮改下这验证码 lucene关键词太长搜索没有结果 我应该下载哪个WebLogic? 为什么不会返回错误的提示框,比如用户名为空的 两套mis系统,一套用B/S结构,一套用C/S结构,两者业务完全相同,在对客户介绍时如何突出B/S系统优点?应从那几个方面说明?? 内部包和外部包的重要区分标准身什么? jsp编聊天师遇到的问题 一个关于Instr函数的问题 在网页上如何提交大文本(超过32k)? 快来抢分100!!!!!!很简单的关于mysql的问题。
<%
try{
String url=new String();
String SQL=new String();
url="jdbc:odbc:geography";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url,"sa","");
SQL="select * from article";
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(SQL);
while(rs.next()){
String count=new String(rs.getString("count"));//这个int类型的可以
out.println(count);
String id=new String(rs.getString("id"));//这个int(identity)类型的出错
out.println(id);
}
rs.close();
con.close();
}
catch(SQLException ex){
while(ex!=null){
out.println("SQLState:"+ex.getSQLState());
out.println("Message:"+ex.getMessage());
out.println("Vendor:"+ex.getErrorCode());
ex=ex.getNextException();
}}%>
如果有把:
Statement stmt=con.createStatement();
改为
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.TYPE_CONCUR_READ_ONLY);试试
用这个试试,
String id=new String(rs.getString(1));
是第2个的话就是:
String id=new String(rs.getString(2));试试吧。
怪了。
try{
String url=new String();
String SQL=new String();
url="jdbc:odbc:geography";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url,"sa","");
SQL="select * from article";
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.TYPE_CONCUR_READ_ONLY); ResultSet rs=stmt.executeQuery(SQL); ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
for (int i=1;i<=cols;i++)
out.print(rsmd.getColumnName(i)+"|");
out.print("<br>");
while(rs.next()){
for (int i=1;i<=cols;i++)
out.print(new String(rs.getObject(i))+"|") ;
out.print("<br>");
//String count=new String(rs.getString("count"));//这个int类型的可以
//out.println(count);
//String id=new String(rs.getString("id"));//这个int(identity)类型的出错
//out.println(id);
}
rs.close();
con.close();
}
catch(SQLException ex){
while(ex!=null){
out.println("SQLState:"+ex.getSQLState());
out.println("Message:"+ex.getMessage());
out.println("Vendor:"+ex.getErrorCode());
ex=ex.getNextException();
}}%>
我将SQL="select * from article";
改为:SQL="select count,id from article";就行了。
看来取值是有顺序的。