「Java」SQLExceptionの使い方

書式
throw new SQLException(xxx)
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
//プレースホルダーuserid
String strSQL ="select * from usertbl where userid = ?";
PreparedStatement pstmt = null;
ResultSet rslt = null;
try {
//CallableStatementオブジェクトを生成
pstmt = conn.prepareCall(strSQL)
pstmt.setString(1,"202107");
//ResultSetオブジェクトを返す
rslt = pstmt.executeQuery();
if(!rslt.next()) {
throw new SQLException("not exist");
}
} catch(Exception e){
throw new SQLException("error" + e.getMessage());
}
//プレースホルダーuserid String strSQL ="select * from usertbl where userid = ?"; PreparedStatement pstmt = null; ResultSet rslt = null; try { //CallableStatementオブジェクトを生成 pstmt = conn.prepareCall(strSQL) pstmt.setString(1,"202107"); //ResultSetオブジェクトを返す rslt = pstmt.executeQuery(); if(!rslt.next()) { throw new SQLException("not exist"); } } catch(Exception e){ throw new SQLException("error" + e.getMessage()); }
//プレースホルダーuserid
String strSQL ="select * from usertbl where userid = ?";

PreparedStatement pstmt = null;
ResultSet rslt = null;
try {

    //CallableStatementオブジェクトを生成    
       pstmt = conn.prepareCall(strSQL)
       pstmt.setString(1,"202107");
       //ResultSetオブジェクトを返す
       rslt = pstmt.executeQuery();
       
       if(!rslt.next()) {
         throw new SQLException("not exist");
       
       }
       
       

 } catch(Exception e){
   throw new SQLException("error" + e.getMessage());
}

 

Java

Posted by arkgame