import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
public class test {
static Connection con=null;
Statement stmt;
public static void main(String[] args) {
if(!db2.conn1("jdbc:odbc:test","sa","13481399975")){
JOptionPane.showMessageDialog(null,"erer");
System.exit(0); }
System.out.println("ok");
String sql="select * from s where sno like ? and sname like ?";
try {
PreparedStatement pstmt = db2.con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
pstmt.setString(1,"%");
pstmt.setString(2,"%");
ResultSet rs = pstmt.executeQuery();
rs.beforeFirst() ;
boolean flag=rs.next();
System.out.println(flag);
System.out.println(rs.getString(1));
} catch (SQLException e) {
e.printStackTrace();
}
}
}
错误:
ok
false
java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 无效的游标状态
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3907)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5698)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:354)
at test.main(test.java:41)