gpt4 book ai didi

Java连接到ipAddress

转载 作者:行者123 更新时间:2023-11-29 02:00:58 24 4
gpt4 key购买 nike

我正在尝试将我的程序连接到我们的主服务器,但它不起作用。当我登录时,这是发生的错误,

Connection error:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Cannot load connection class because of underlying exception:
'java.lang.NumberFormatException:For input string:"192.168.10.105"'.

这是我的代码,在我将它连接到服务器数据库的类中:

package login;
import java.sql.*;
import javax.swing.JOptionPane;


public class DatabaseCls {

public Connection con;
private void conData() {
try {

String host = "jdbc:mysql://ipAddress:192.168.10.105/eqod-log";
String uName = "localhost";
String uPass= "eq0d.c0m";


con = DriverManager.getConnection(host, uName, uPass);
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, e, "Connection Error", JOptionPane.ERROR_MESSAGE);
}
}

public ResultSet rsFetch(String query) {
ResultSet rs = null;
try {
conData();
rs = con.createStatement().executeQuery(query);
return rs;
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, e, "ResultSet Query Error", JOptionPane.ERROR_MESSAGE);
return rs;
}
}

public boolean exSQL(String query) {
boolean done;
try {
done = true;
conData();
con.createStatement().execute(query);
con.close();
return done;
}
catch(Exception e) {
done = false;
JOptionPane.showMessageDialog(null, e, "Query Error", JOptionPane.ERROR_MESSAGE);
return done;
}
}
}

你能帮我解决这个问题吗,我是 java 的新手

最佳答案

    String host = "jdbc:mysql://192.168.10.105:3306/eqod-log"; //3306 is port 

使用这个字符串作为连接 url。更多详情 JDBC URL Format

关于Java连接到ipAddress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14972334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com