How to check the correct installation of the JDBC driver and the ability to connect the database?

I tried installing this at home with the Java SDK ... the SDK worked fine, and now I can use the command line to compile java programs into classes ...

However, I'm not sure how to check if JDBC works to connect to my server / databases / mysql.

How I feel my server (which is the shared website / web host) may not allow the connection ...

How can I verify that JDBC is installed correctly without connecting to the server?

And then how can I verify (please, separate code) that (now confirmed working) JDBC connects to my databases?

Thank you so much.

+6
source share
3

   JDBC ?

, Class#forName() JDBC ClassNotFoundException.

try {
    Class.forName(driverClassName);
    // Success.
}
catch (ClassNotFoundException e) {
    // Fail.
}

, (, ), ( ) JDBC ?

, DriverManager#getConnection() DataSource#getConnection() SQLException.

try (Connection connection = DriverManager.getConnection(url, username, password)) {
    // Success.
}
catch (SQLException e) {
    // Fail.
}

+14

MySQL JDBC- - .

-, Java-,

Class.forName("com.mysql.jdbc.Driver");

, .

-, , :

Connection conn =  DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","user", "pass");

URL, .

+2

Install the local database and connect to it.

You can check the connection to the server using telnet to connect to the port where the database should be listened to; if you can open the connection, you know that there is no network problem (such as a firewall). If JDBC is OK and the network is OK, then you can try connecting to the remote system. If this does not work, this is a configuration issue.

+1
source

All Articles