I recently studied JDBC (Java Database Connectivity) a little. I searched only one case from the database, and I was troubled with the conditional branching method when getting the result, so I will leave it as a memo.
Connection con = null;
Statement stmt = null;
ResultSet res = null;
String sql = "SELECT * FROM DATABASE WHERE COLUMN = 〇〇";
try{
    con.DriveManager.getConnection(url, user, password);
    stmt.con.createStatement();
    res.stmt.executeQuery(sql);
    if(res.next()){
        //Processing when there is a result
    }else{
        //Processing when there is no result
}catch(SQLException e){
    //Processing when the SQL statement is incorrect
}finally{
    //Close processing etc.
}
        Recommended Posts