ResultSet rs =pStmnt.executeQuery() devolverá un conjunto de resultados que nunca será nulo hasta que no haya ninguna excepción. Si desea verificar si hay registros, puede usar el método rs.next() para verificar si hay registros o no. conjunto de resultados
public boolean createRecord(Myuser myuser)
{
Connection cnnct = null;
PreparedStatement pStmnt = null;
try
{
cnnct = getConnection();
String preQueryStatement
= "SELECT * FROM MYUSER WHERE MYUSER.USERID = ?;";
pStmnt = cnnct.prepareStatement(preQueryStatement);
pStmnt.setLong(1,youruserid);
ResultSet rs = pStmnt.executeQuery();
if (!rs.next())
{
String insertStatement
= "INSERT INTO MYUSER VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement ps = cnnct.prepareStatement(insertStatement);
ps.setString(1, myuser.getUserid());
ps.setString(2, myuser.getName());
ps.setString(3, myuser.getPassword());
ps.setString(4, myuser.getEmail());
ps.setString(5, myuser.getPhone());
ps.setString(6, myuser.getAddress());
ps.setString(7, myuser.getSecQn());
ps.setString(8, myuser.getSecAns());
System.out.println("new user inserted");
return true;
}
else
{
System.out.println("user already in data base");
return false;
}
}
catch (SQLException ex)
{
while (ex != null)
{
ex.printStackTrace();
ex = ex.getNextException();
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
finally
{
if (pStmnt != null)
{
try
{
pStmnt.close();
}
catch (SQLException e)
{
}
}
if (cnnct!= null)
{
try
{
cnnct.close();
}
catch (SQLException sqlEx)
{
}
}
}
}