+ 1
How do i avoid it?
I am coding in java related to jdbc. However I get "null" when I want to display data after picking it up from my database. I took care to check that my query was correct and that the data did indeed exist in my MySQL database. Here a part of my code to do it: Statement state=con.createStatement(); String recu="Select name from table where id=1"; ResultSet rs=state.executeQuery(recu); While(rs.next()){ String h=rs.getString(0); } System.out.println(h);
5 Antworten
+ 3
By getting "name" is not a good idea because somehow if you drop column name then you have to change in code as well which is not a good idea.
We should avoid to right direct query in code. Stored Procedure is a better option.
+ 2
Romaric
Your code is right but I think there should be
rs.getString(1);
+ 1
Jayakrishna🇮🇳 Thanks , i take note
0
Statement state=con.createStatement();
String recu="Select name from table where id=1";
ResultSet rs=state.executeQuery(recu);
while(rs.next()){
String h=rs.getString(1);
System.out.println(h);
}
//Romaric column index starts from 1
0
FF9900 okay thanks foy ur contribution