这是我的代码
<%
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:firstdb";
conn = DriverManager.getConnection(url,"admin3","admin3");
stmt=conn.createStatement();
String sql="select * from goodinf";
rs=stmt.executeQuery(sql);
while(rs.next()){
%>
<tr>
<th scope="col"><%=rs.getObject(1) %></th>
<th scope="col"><%=rs.getObject(2) %></th>
<th scope="col"><%=rs.getObject(3) %></th>
<th scope="col"><%=rs.getObject(4) %></th>
<th scope="col"><%=rs.getObject(5) %></th>
<th scope="col"><%=rs.getObject(6) %></th>
<th scope="col"><%=rs.getObject(7) %></th>
<th scope="col"><%=rs.getObject(8) %></th>
<th scope="col"><%=rs.getObject(9) %></th>
<th scope="col"><a href="del.jsp?age=<%=rs.getObject(1)%>">删除</a></th>
</tr>
<%
}
}catch(SQLException e){
e.printStackTrace();
}
%>
就这个链接总是连不上,不知道是为什么
[此贴子已经被作者于2007-4-8 15:04:08编辑过]
----------------解决方案--------------------------------------------------------
写法没错只是你直接getObject,应该还要转化成相对应的类型。
----------------解决方案--------------------------------------------------------
谢谢,弄明白了
----------------解决方案--------------------------------------------------------
是因为你创建的数据集默认是TYPE_FORWARD_ONLY的,你只能rs.getObject(1)一次,再次读会出错了。
你需要创建时候用
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
或者你提前把数据读出来用变量记录,然后下面使用你定义的变量就可以了!
----------------解决方案--------------------------------------------------------