Java通过JDBC远程连接mySQL:ODBC桥
我在使用 Java 远程连接到 mySQL 数据库时遇到问题。这是我的错误消息:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] 未找到数据源名称并且未指定默认驱动程序
我确定我的 IP 地址和地址我正在使用工作端口,因为我使用相同的 ip & mySQL 客户端程序的端口。
我的托管公司不支持 JDBC,因此我使用 JDBC-ODBC 桥接器。
这是我的课程:
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);
}
}
错误发生在这一行: con = DriverManager.getConnection(url, 用户, pass);
我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ODBC 中,通常在 URL 中使用数据源名称 (DSN),而不是主机名:端口。如果托管文档中对此不清楚和/或无法直接透露,那么您需要联系他们以获取确切的 DSN。一旦知道,请使用以下 URL:
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: