Having trouble with this..I’m sure I’m missing something simple but I simply want the result of a select statement in a java mysql select statement but I keep getting:
com.mysql.jdbc.JDBC4ResultSet@1c190c99
Here’s my code:
PreparedStatement Findstatement;
Findstatement = con.prepareStatement("SELECT Code from DataMaster where DataName= (?) ");
Findstatement.setString(1, Name); // I have a variable in my file named 'Name'
ResultSet CodeAll = Findstatement.executeQuery();
System.out.println(CodeAll);
I’ve tried int fundCode = fundCodeAll.getInt(1); at the end of the statement but still no luck. How do I get the int value of the the result from the select statement?
You need to iterate over the
ResultSetbyResultSet#next()and then get the column values by any of theResultSetgetters.If there are zero or many results, then you can collect them in a
List.Or if there is zero or one result, then replace
whilebyif.See also:
Unrelated to the concrete problem, please pay attention to the Java naming conventions.