What's wrong with this code? It gives me "brand" = null.
public String getBrand(@WebParam(name = "regNr") String regNr) throws SQLException {
String brand=null;
Connection con;
Statement st;
ResultSet rs;
String url = "jdbc:mysql://db4free.net:3606/cars";
String user = "cars";
String password = "";
try {
con = (Connection) DriverManager.getConnection(url, user, password);
st = (Statement) con.createStatement();
rs = st.executeQuery("SELECT * FROM Cars WHERE nr= '" + regNr + "'");
if (rs.next()) {
brand=rs.getString("brand");
}
} catch (SQLException ex) {
}
return brand;
}
I want to display the value of brand from database. Is it a problem with connection?