|
Based on CONJ-64, I've tried to set up my MySQL Server with a self-signed certificate and use the MariaDB Java Client 1.1.5 to connect to it.
I'm using the following code:
public static void main(String[] args)
|
{
|
try
|
{
|
Class.forName("org.mariadb.jdbc.Driver").newInstance();
|
String url = "jdbc:mysql://localhost:3306/test";
|
|
Properties info = new Properties();
|
info.setProperty("user", "root");
|
info.setProperty("password", "");
|
info.setProperty("serverSslCert", "C:\\cert.pem");
|
info.setProperty("useSSL", "true");
|
|
Connection conn = DriverManager.getConnection(url, info);
|
Statement st = conn.createStatement();
|
st.executeQuery("SELECT * FROM tbl");
|
|
conn.close();
|
}
|
catch (ClassNotFoundException ex) {System.err.println(ex.getMessage());}
|
catch (IllegalAccessException ex) {System.err.println(ex.getMessage());}
|
catch (InstantiationException ex) {System.err.println(ex.getMessage());}
|
catch (SQLException ex) {System.err.println(ex.getMessage());}
|
}
|
The database "test" exists and contains a table called "tbl".
When I run this code, it throws an exception at executeQuery stating "No database selected". All works well when commenting out setProperty("useSSL", "true"). I can also "fix" the problem by changing the SQL query to "SELECT * FROM test.tbl", but this is really not what I want.
This issue is independent of the MySQL Server as I've tried it with 5.0.67-community-nt and 5.5.34-0ubuntu0.12.04.1. Both have been set up with the same SSL certificate.
|