0
你好下面是我的jdbc代碼在這裏我想插入一個記錄到遠程機器,當我使用相同的代碼與本地數據庫服務器我能夠成功地插入記錄。但是當我嘗試使用遠程機器時,它會拋出以下錯誤。在遠程sql服務器中插入記錄
請確定我傳遞給創建連接的參數是否足夠,需要添加其他的東西。
錯誤::當進出口運行上面的代碼,得到如下異常
也讓我知道,如果連接的詳細信息,即時通訊傳遞的網址都夠使連接都需要添加一些別的東西。
爲了連接到遠程sql服務器,只有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.