[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 393
  • Last Modified:

Unable to access mysql database through JDBC Connection string

We have a Cpanel User Account, through which we are able to login and able to access the cpanel features, when we using this user account through JDBC connection string, we are unable to access the mysql database. Then what precautions has to be take when using the JDBC connection string ?
  • 2
1 Solution
Ok, I've not got alot of information to go on here, but I'll try to help.

Obviously, you should import java.sql.*;

What JDBC connector are you using?  I'd suggest Connector/J
(you can find it at http://dev.mysql.com/downloads/connector/j/3.1.html)

In your accessing class, you need to declare the driver using the following code:

//The newInstance() call is a work around for some broken Java implementations

Then you'll need to obtain a connection for the database using the following code:

String url = "jdbc:mysql:http://hostname.domain/database_name";
Connection con = DriverManager.getConnection(url, "username", "password");

Updates and Queries to the database can be made using the Statement type.
e.g.  Statement stmt = con.createStatement();

The syntax for this is: stmt.executeUpdate(String_name); where 'String_name' is
the sql command to update the table.

there is also stmt.executeQuery.  you'll need to create a ResultSet to retrieve the
results from this.

Hope this helps.

oops, the url String in the above is incorrect.

it should read: String url = "jdbc:mysql://hostname.domain/database_name";

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now