【发布时间】:2016-03-07 01:28:39
【问题描述】:
您好,下面是我的 jdbc 代码,我想在远程机器中插入一条记录,当我使用与本地数据库服务器相同的代码时,我能够成功插入记录。但是当我尝试使用远程机器时,它会抛出以下错误。
请告诉我为创建连接传递的参数是否足够需要添加一些其他东西。
错误:: 当我运行上面的代码时,遇到异常
如果我在 url 中传递的连接细节是否足以建立连接,是否需要添加其他内容。
为了连接到远程sql server,只需要jdbc代码就足够了,或者应该开发成web应用程序。
有人请告诉我我需要做什么来解决这个问题!
谢谢
public class JdbcTestClass {
public static void main(String [] args) throws SQLException
{
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection("jdbc:mysql://120....:3306/example","root","root");
Statement st = con.createStatement();
st.executeUpdate("insert into test.student values(9966,'pradeep',93);");
System.out.println("Record Inserted Successfuly :: ");
if(st != null)
{
st.close();
System.out.println("connection closed successfuly :: "+st);
}
if(con != null)
{
con.close();
}
}
catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("Error In 1st try :: "+e);
}
}
}
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure Last packet sent to the server was 0 ms ago.
【问题讨论】: