Java应用程序无法以debian中的非root用户身份连接到mysql

时间:2011-06-05 10:52:22

标签: java mysql debian

请参阅Stumped SQL Exception for JDBC

作为非root debian用户运行时,我有类似的错误(如下所列)。但是,如果java应用程序在debian中以root用户身份运行,则不会发生此错误。

应用程序配置为以root用户身份连接到mysql。

我按照推荐问题中的建议在my.cnf中添加以下条目后重启系统。但是会发生同样的错误。

character_set_server=utf8
collation_server=utf8_general_ci

请帮忙。

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:1026)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
   at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1751)
   at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3425)
   at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2045)
   at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:718)
   at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
   at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
   at java.sql.DriverManager.getConnection(libgcj.so.10)
   at java.sql.DriverManager.getConnection(libgcj.so.10)
   at org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:65)
   at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
   at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:840)
   at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:96)
   at edu.amrita.jdbc.connectionpool.bundle.DBConnectionPoolImpl.getConnection(DBConnectionPoolImpl.java:95)
   at edu.amrita.devicetalk.protocol.aesccmp.DatabaseInterface.getRegisteredDevices(DatabaseInterface.java:116)

1 个答案:

答案 0 :(得分:0)

确保非root用户使用sun-java6-jdk命令(以root身份)使用来自非免费的Oracle Java(sun-java6-jreupdate-alternatives包):

# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                  Priority   Status
------------------------------------------------------------
* 0            /usr/bin/gij-4.4                       1044      auto mode
  1            /usr/bin/gij-4.4                       1044      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java   63        manual mode

Press enter to keep the current choice[*], or type selection number: 

选择合适的号码(此处为2)。之后应该有:

$ java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)