gpt4 book ai didi

java - CentOS服务器com.mysql.jdbc.exceptions.MySQLSyntaxErrorException异常

转载 作者:行者123 更新时间:2023-11-29 01:04:23 25 4
gpt4 key购买 nike

在CentOS服务器上运行java代码连接mysql

我的代码是-

String server = "", url = "", password = "", user = "", databasename = "";
Connection con = null;
try {
server = "xxx.xxx.xxx.xxx";
databasename = "xx";
user = "user";
password = "pass";
Class.forName("com.mysql.jdbc.Driver");
url = "jdbc:mysql://" + server + "/" + databasename + "";
con = DriverManager.getConnection(url, user, password);
System.out.println(server + " Database connection established");
System.out.println(con);
} catch (Exception e) {
System.out.println("***************connection failed********************");
e.printStackTrace();
}

我的数据库在同一台服务器上运行。

我在我的本地系统和其他服务器上为同一个数据库运行这段代码,它运行良好,但它没有在我的数据库可用的同一台服务器上运行。我收到此异常 -

    com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??????????????' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1027)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3361)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3295)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1852)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1975)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2470)
at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1669)
at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3336)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1979)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:287)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
at java.sql.DriverManager.getConnection(libgcj.so.10)
at java.sql.DriverManager.getConnection(libgcj.so.10)
at testthread.ConnectionFactory.getConnection(ConnectionFactory.java:28)
at testthread.ConnectionFactory.main(ConnectionFactory.java:39)

谁能帮我看看这是什么问题。

最佳答案

这个问题看起来和下面的很相似: Stumped SQL Exception for JDBC

尝试检查本地数据库服务器中的字符集配置/数据

关于java - CentOS服务器com.mysql.jdbc.exceptions.MySQLSyntaxErrorException异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11577039/

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