当前位置: 技术问答>java相关
又是菜鸟问题
来源: 互联网 发布时间:2015-06-06
本文导语: 运行到rst.beforeFirst();就SQLException 为什么??? public void dataSelect() { String sqlLanguageString = new String(); try { Class.forName(driverString); con...
运行到rst.beforeFirst();就SQLException 为什么???
public void dataSelect()
{
String sqlLanguageString = new String();
try
{
Class.forName(driverString);
con = DriverManager.getConnection(conString);
stmt = con.createStatement();
sqlLanguageString ="select * from tbn";
ResultSet rst = stmt.executeQuery(sqlLanguageString);
rst.beforeFirst();/********/
while(rst.next())
{
String outputHead = rst.getString("headname");
String outputValue = rst.getString("headvalue");
System.out.println("head:" + outputHead
+ "value:" + outputValue);
}
rst.close();
stmt.close();
con.close();
}
catch(ClassNotFoundException e)
{
System.out.print("ClassNotFoundException occur when connect to database!");
}
catch(SQLException e)
{
System.out.print("SQLException occur when output data!");
}
}
public void dataSelect()
{
String sqlLanguageString = new String();
try
{
Class.forName(driverString);
con = DriverManager.getConnection(conString);
stmt = con.createStatement();
sqlLanguageString ="select * from tbn";
ResultSet rst = stmt.executeQuery(sqlLanguageString);
rst.beforeFirst();/********/
while(rst.next())
{
String outputHead = rst.getString("headname");
String outputValue = rst.getString("headvalue");
System.out.println("head:" + outputHead
+ "value:" + outputValue);
}
rst.close();
stmt.close();
con.close();
}
catch(ClassNotFoundException e)
{
System.out.print("ClassNotFoundException occur when connect to database!");
}
catch(SQLException e)
{
System.out.print("SQLException occur when output data!");
}
}
|
beforeFirst方法使用错误:
Moves the cursor to the front of this ResultSet object, just before the first row
去掉这句就行。
对你的程序要求没有影响。
Moves the cursor to the front of this ResultSet object, just before the first row
去掉这句就行。
对你的程序要求没有影响。
|
你把rst.beforeFirst();删掉看看出什么错
另外,你得把错误信息贴出来呀
另外,你得把错误信息贴出来呀