String sql = "select s_upload_file.NEXTVAL from dual" ;
PreparedStatement ps = con.preparedStatement(sql);
ResultSet rs = ps.executeQuery();
执行此操作时,我得到的结果集为空。这是什么问题。
答案 0 :(得分:1)
您可以通过rs.next()
获取值,
String sql = "select s_upload_file.NEXTVAL from dual";
PreparedStatement pst = conn.prepareStatement(sql);
synchronized( this ) {
ResultSet rs = pst.executeQuery();
if(rs.next())
long nxtVal = rs.getLong(1);
}
答案 1 :(得分:1)
已经有很多答案,但是我会尽力为您提供完整的答案。
public static Connection getConnection_Test() throws Exception{
try{
String driver = "com.mysql.cj.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/Database_Name";
String username = "root";
String pass = "";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, pass);
System.out.println("Success!");
String query = "SELECT S_UPLOAD_FILE.NEXTVAL from dual \n ";
PreparedStatement st = conn.prepareStatement(query);
ResultSet rs = st.executeQuery();
while(rs.next()){
int NEXTVALUE = rs.getInt(1);
System.out.println(NEXTVALUE);
}
rs.close();
st.close();
return conn;
}catch (Exception e){
System.out.println(e);
}
return null;
}
答案 2 :(得分:0)
您尝试过这样的事情吗?
/* not mandatory but give an alias to your column in select */
if(rs.next()){
int nextval = rs.getInt(1);
System.out.println(nextval)
}
答案 3 :(得分:0)
您应该尝试类似的事情
String sql = "select s_upload_file.NEXTVAL from dual" ;
PreparedStatement ps = con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
if (rs.next())
{
int var2= rs.getInt(1);
}