Reputation: 1
I am having problems remotely connecting to my mySQL database in Java. Here is my error message:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I am sure my ip address & port I am using work, since I am using the same ip & port for a mySQL client program.
My hosting company do not support JDBC so I am using a JDBC-ODBC bridge.
Here is my class:
public class SQLdataBase {
private Connection con;
private Statement st;
private static final String url="jdbc:odbc://xxx.xxx.xxx.xxx:3306";
private static final String className="sun.jdbc.odbc.JdbcOdbcDriver";
private static String user;
private static String pass;
SQLdataBase(String userName, String password) {
user=userName;
pass=password;
try {
Class.forName(className);
con = DriverManager.getConnection(url, user, pass);
System.out.println("success");
st = con.createStatement();
} catch (Exception ex) {
System.out.println(ex);
}
//do whatever database processing is required
}
public void queryNoReturn(String query) throws SQLException{
st.executeQuery(query);
}
}
The error occures at this line: con = DriverManager.getConnection(url, user, pass);
What am I doing wrong?
Upvotes: 0
Views: 6784
Reputation: 1108612
String url="jdbc:odbc://xxx.xxx.xxx.xxx:3306";
In ODBC, you normally use the data source name (DSN) instead of hostname:port in URL. If this is unclear and/or not directly revealable in the documentation of the hosting, then you'll need to contact them for the exact DSN. Once known, then use the following URL:
String url="jdbc:odbc:dataSourceName";
Upvotes: 1