jacky jacky - 3 months ago 14
Java Question

Getting MySql command result in servlet java

Basically I am trying to find how many people in mysql database are registered by a specific name using

SELECT
command with my java program. The command executes without any error but the result is something different than I have in my db.

Here is my java code I am using to get UIDs:

public void usernameAvail_fun(){
String query = "SELECT UID FROM db.tb WHERE UFN=\"myuid\"";
ResultSet ursa;
try {
ursa = st.executeQuery(query);
System.out.println(ursa.toString());
} catch (SQLException e) {
e.printStackTrace();
}
}


and i happen to get the result as:
com.mysql.jdbc.JDBC42ResultSet@11719758

Answer

You are printing a java object so output is there. If you want to print uid use following statement -

while (ursa.next()){
    System.out.println(ursa.getString(1));
}
Comments