数据库连接java桌面应用程序的问题 [英] problem in database connection java desktop app
本文介绍了数据库连接java桌面应用程序的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这段代码中,我尝试将我的java程序连接到存储在xtreemhost网站上的MySQL数据库但是我不能帮助我解决这个问题
In this code i tried to connect my java program to MySQL database that stored on xtreemhost website but i cant.please help me to solve this
Connection con = null;
String url = "jdbc:mysql://sql108.xtreemhost.com/";
String db = " xth_10161434_pos";
String driver = "com.mysql.jdbc.Driver";
String user = "xth_10161434";
String pass = "*****";
try{
Class.forName(driver);
con =(Connection) DriverManager.getConnection(url+db, user, pass);
Statement st = (Statement) con.createStatement();
ResultSet rs=st.executeQuery("SELECT * FROM xth_10161434_pos.product LIMIT 0 TO 30;");
while(rs.next())
{
System.out.println(rs.getString(2));
}
}
catch(Exception e)
{
System.out.println(e);
}
显示例外情况:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败
成功发送到服务器的最后一个数据包是0毫秒前。驱动程序没有从服务器收到任何数据包。
Showing an Exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
推荐答案
您应该使用自己的MySQL进行测试。为此使用外部服务器是不正确的。由于误叫,该服务的提供商可能会阻止您。
查看XAMPP [ ^ 一>]。它是免费的,易于使用(你可以简单地打开和关闭它),并为你的本地主机提供一个完整的网络服务器,包括MYSQL。
You should use your own MySQL for testing. It is not a valid thing to use a foreign server for that. It might be possible that the provider of that service is blocking you due to false calls.
Check out XAMPP[^]. it's free, easy to use (you can simply switch it on and off) and will give you a complete webserver including MYSQL for your localhost.
plS CHK THIS LINK
http://jdbcerrorinfo.blogspot.com/20...mysqljdbc.html
plS CHK THIS LINK
http://jdbcerrorinfo.blogspot.com/20...mysqljdbc.html
这篇关于数据库连接java桌面应用程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文