this is my code
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/records";
Connection con = DriverManager.getConnection(url,"root","");
Statement st = con.createStatement();
String sql = "SELECT * FROM patient_info WHERE name = '"+txt1.getText()+"' ";
in this part it always print true , if im right this boolean returns the boolean value of string sql
Boolean ret = st.execute(sql);
System.out.println(ret.toString());
this if statement i dont know if right
if(ret == true){
ResultSet rs = st.executeQuery(sql);
String name = null;
while(rs.next()) {
name = rs.getString("name");
txt2.setText(name);
System.out.println("working");
}
rs.close();
}else{
txt2.setText("no records");
System.out.println("no records");
}
st.close(); con.close();
}catch(SQLException e){
e.printStackTrace();
}catch(ClassNotFoundException e){
e.printStackTrace();
}
Aucun commentaire:
Enregistrer un commentaire