The database server is mysql 5 and is mounted on a Centos server, the connection to the database do the form.
Code:
public static Connection getConnectionDB () (
if (conn == null)
connect ();
try (
if (conn! = null)
if (Conn. isClosed ()) (
conn = null;
System.out.println ("not connected");
)
) Catch ( SQLException e) (
System.out.println ("isClosed");
)
return conn;
)
public static Connection connect () (
try (
Class.forName (driver);
) Catch ( ClassNotFoundException e) (
System.out.println ("Driver");
)
try (
conn = DriverManager.getConnection (url + db, user, pass);
) Catch ( SQLException e) (
conn = null;
JOptionPane . showMessageDialog (null, "Unable to connect to server");
System.gc ();
)
return conn;
)
public boolean close () (
try (
conn.close ();
conn = null;
return true;
) Catch ( SQLException e) (
e.printStackTrace ();
return false;
)
)
Bookmarks