本文介绍了数据库连接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.
推荐答案
这篇关于数据库连接java桌面应用程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!