devi inserire un try e cacht per gestire gli errori in caso che qualcosa non vada a buon fine.
con l'if non riesci a gestire niente
ti posto il codice che utilizzo di solito:
[code]
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance ();
String ipnumber ;
ipnumber = "127.0.0.1 ";
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/NOME_DEL_DATABASE?user=root");
if(!con.isClosed())
jTA1.setText("Successfully connected to " +
"MySQL server using TCP/IP...");
String qrty = "select * from Tb_Utenti";
Statement cmd = con.createStatement();
//ResultSet rs = cmd.
} catch(Exception e) {
jTA2.setText("Exception: " + e.getMessage()); // QUI SE VUOI SCRIVI
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}