用java连接数据库,表中有数据,但查询不出来,请教一下
public Connection getConn() throws SQLException {
String sDBDriver = "oracle.jdbc.driver.OracleDriver";
String sConnStr = "jdbc:oracle:thin:@zhwlcool:1521:fyt";
Connection conn = null;
String user="scott";
String pass="ch111111";
try {
Class.forName(sDBDriver);
conn=DriverManager.getConnection(sConnStr,user,pass);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
public PreparedStatement getPreparedStatement(String sql)throws SQLException{
Connection conn=getConn();
PreparedStatement pst=conn.prepareStatement(sql);
return pst;
}
public static void main(String [] args) throws SQLException{
TestConn tconn = new TestConn();
try{
PreparedStatement pst=tconn.getPreparedStatement("select * from gtestsomething");
if(pst!=null){
ResultSet rs=pst.executeQuery();
if(rs.next()){//此处为什么为false
System.out.println(rs.getString(2));
}
rs.close();
}
pst.close();
}catch(Exception e){
e.printStackTrace();
}
}
用pl/sql执行“select * from gtestsomething”表gtestsomething中有两列数据,为什么rs.next()){一直为false呢