public void searchStudentDetails() throws SQLException {
DatabaseConnection dbms=new DatabaseConnection("jdbc:mysql://localhost:3306/Studentdb","root","root");
Connection con= dbms.getConnection();
Scanner obj=new Scanner(System.in);
System.out.println("Enter your name:");
String inputname=obj.next();
String sql="select *from student where name=? ";
PreparedStatement stmt=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
stmt.setString(1, inputname);
ResultSet rs=stmt.executeQuery();
if(rs.next() ==false)
{
System.out.println("no such data is found");
}
else
{
while(rs.next())
{
rs.previous();
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getInt(4));
}
}
stmt.close();
con.close();
}
Output: in console, it shows nothing.
when I enter the wrong name if() condition is working fine but else condition does not fetch any data any modifications?