Class.forName( "com.mysql.jdbc.Driver ").newInstance();
Connection connection=DriverManager.getConnection( "jdbc:mysql://localhost/shujuku ", "root ", "3325490 ");
Statement stat = connection.createStatement();
ResultSet rs = stat.executeQuery( "SELECT * FROM biao1 ");
out.print(rs.getString( "name ")); //为什么在这加条语句就报错?
while(rs.next()) {
out.print(rs.getString( "name "));
out.print(rs.getString( "name "));
}
out.print(rs.getString( "name ")); //而把语句放在这个位置就不报错呢?
请各位高手指点一二,小弟感激涕零!
------解决方案--------------------
lz直接调用:
out.print(rs.getString( "name ")); //为什么在这加条语句就报错?
此时,ResultSet结果集游标指向第一行之前当然会报错。
应当先让游标下移到结果集第一行再取记录:
if(rs.next())
{
out.print(rs.getString( "name "));
}