I have a mysql table named 'customer'. serialnumber (int), name(varchar), gender(varchar) are the table fields.
I have a int variable a = 2.
I want to fetch the value from the table when serialnumber = a. That is when the serialnumber = 2 it should display the particular customer's name.
String url="jdbc:mysql://localhost/shopping";
String usr ="root";
String pass = "rootpassword";
session.setAttribute( "URL", url );
session.setAttribute( "user", usr );
session.setAttribute( "passwd", pass );
String connectionURL = (String)session.getAttribute( "URL" );
String user = (String)session.getAttribute("user");
String passwd = (String)session.getAttribute("passwd");
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, user, passwd);
statement = connection.createStatement();
rs=statement.executeQuery("select * from customer where serialnumber like '%a%' ");
while (rs.next()) {
out.println("Customer Name: ");
out.println(rs.getString("name"));
}rs.close();
}catch(Exception ce){out.println(ce);}
}
This throws me nothing. But when i give the number instead a in rs.execute Query it displays the customer name. How to solve this and what is my mistake??
Thanks