【问题标题】:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException exception in CentOS serverCentOS 服务器中的 com.mysql.jdbc.exceptions.MySQLSyntaxErrorException 异常
【发布时间】:2012-07-19 14:15:07
【问题描述】:

在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)

有没有人帮我看看有什么问题。

【问题讨论】:

  • 您正在运行什么 SQL 查询?你会发吗?
  • 帮不上忙,因为没有显示导致问题的代码。对我来说,这看起来像是糟糕的 SQL 语法。转到堆栈跟踪告诉您的行是问题的根源并查看。
  • @Triclosan:没有运行任何查询,只是连接到在同一台服务器上运行的 mysql 数据库。
  • @Duffmo: con = DriverManager.getConnection(url, user, password);在这一行得到这个异常。
  • ` jdbc:mysql://localhost:3306/` 你在哪里提到端口号???服务器字符串是否包含端口号????还将您的 url 更改为 --> ` url = "jdbc:mysql://" + server + "/" + databasename; `JDBC CONNECTION你有没有使用任何??????????????在你的 sql 查询中???

标签: java mysql database-connection centos


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2017-03-17
    • 2013-03-05
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-14
    相关资源
    最近更新 更多