Clojure MySQL语法错误异常(“[…]附近? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?“[…]”)

时间:2021-08-05 00:31:56

I'm having trouble doing anything with clojure.contrib.sql beyond establishing a connection.

我做任何事都有困难。除了建立连接之外的sql。

I have a mysqld running on localhost:3306 with a database called clj_db. The user 'clj_user'@'localhost' with password 'clj_pass' can access this database.

我有一个在localhost:3306上运行的sqmyld,数据库名为clj_db。用户“clj_user”@“localhost”和密码“clj_pass”可以访问这个数据库。

When trying to "select * from clj_table" I get a "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".

在尝试“从clj_table中选择*”时,我得到一个“com.mysql.jdbc.exception”。MySQLSyntaxErrorException: SQL语法中有错误;请检查与MySQL服务器版本对应的手册,以获得使用near '?????????????在1号线”。

What am I doing wrong?

我做错了什么?

clj_db.clj_table

clj_db.clj_table

CREATE TABLE `clj_table` (
  `col_one` int(11) NOT NULL,
  `col_two` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

mysql_test.clj

mysql_test.clj

(ns test.mysql
    (:use clojure.contrib.sql)
)

(def db-settings
    {:classname "com.mysql.jdbc.Driver"
    :subprotocol "mysql"
    :subname "//localhost:3306/clj_db"
    :user "clj_user"
    :password "clj_pass"})

(with-connection db-settings
    (with-query-results rs ["select * from clj_table"]
        (dorun (map #(println (:col_one :col_two %)) rs))
    ))

Output

输出

Exception in thread "main" 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 (mysql_test.clj:0)
   at clojure.lang.Compiler.eval(Compiler.java:4658)
   at clojure.lang.Compiler.load(Compiler.java:4972)
   at clojure.lang.Compiler.loadFile(Compiler.java:4939)
   at clojure.main$load_script__7405.invoke(main.clj:213)
   at clojure.main$script_opt__7442.invoke(main.clj:265)
   at clojure.main$main__7466.doInvoke(main.clj:346)
   at clojure.lang.RestFn.invoke(RestFn.java:441)
   at clojure.lang.Var.invoke(Var.java:367)
   at clojure.lang.AFn.applyToHelper(AFn.java:179)
   at clojure.lang.Var.applyTo(Var.java:476)
   at clojure.main.main(main.java:37)
Caused by: 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:1048)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3563)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3495)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2687)
   at com.mysql.jdbc.ConnectionImpl.configureClientCharacterSet(ConnectionImpl.java:1859)
   at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3593)
   at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2199)
   at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:784)
   at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:350)
   at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:284)
   at java.sql.DriverManager.getConnection(libgcj.so.10)
   at clojure.contrib.sql.internal$get_connection__218.invoke(internal.clj:85)
   at clojure.contrib.sql.internal$with_connection_STAR___226.invoke(internal.clj:102)
   at test.mysql$eval__386.invoke(mysql_test.clj:12)
   at clojure.lang.Compiler.eval(Compiler.java:4642)
   ...10 more

3 个解决方案

#1


2  

I've switched to Sun's JDK6 instead of GIJ.

我换成了Sun的JDK6而不是GIJ。

I got "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure". I found this thread, which really helped me a lot.

我有“com.mysql.jdbc.exceptions.jdbc4。CommunicationsException:通信链路失败”。我找到了这条线,这对我帮助很大。

I've added the option "-Djava.net.preferIPv4Stack=true" and it now works fine.

我添加了选项“-Djava.net.preferIPv4Stack=true”,现在它工作得很好。

Thanks everybody!

谢谢大家!

#2


1  

I was having the exact same problem only I was using Java. I found this post and the solution described there worked for me.

我也有同样的问题,只是我用的是Java。我找到了这篇文章,上面描述的解决方案对我很有效。

The trick was to add "useJvmCharsetConverters=true" to the end of the connection-string.

诀窍是在连接字符串的末尾添加“usejvmcharsetconverter =true”。

#3


0  

the code looks very similar to the (presumably working) code in This Question
perhaps its a problem with the version of clojure-contrib.

在这个问题中,代码看起来与(可能是工作的)代码非常相似,这可能是clojure- managed版本的问题。

when I macroexpand the code from these two question they come out the same so it seems likely that the problem is not with the contents of mysql_test.clj.

当我从这两个问题中对代码进行宏展开时,它们的结果是一样的,所以看起来问题不在于mysql_test.clj的内容。

#1


2  

I've switched to Sun's JDK6 instead of GIJ.

我换成了Sun的JDK6而不是GIJ。

I got "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure". I found this thread, which really helped me a lot.

我有“com.mysql.jdbc.exceptions.jdbc4。CommunicationsException:通信链路失败”。我找到了这条线,这对我帮助很大。

I've added the option "-Djava.net.preferIPv4Stack=true" and it now works fine.

我添加了选项“-Djava.net.preferIPv4Stack=true”,现在它工作得很好。

Thanks everybody!

谢谢大家!

#2


1  

I was having the exact same problem only I was using Java. I found this post and the solution described there worked for me.

我也有同样的问题,只是我用的是Java。我找到了这篇文章,上面描述的解决方案对我很有效。

The trick was to add "useJvmCharsetConverters=true" to the end of the connection-string.

诀窍是在连接字符串的末尾添加“usejvmcharsetconverter =true”。

#3


0  

the code looks very similar to the (presumably working) code in This Question
perhaps its a problem with the version of clojure-contrib.

在这个问题中,代码看起来与(可能是工作的)代码非常相似,这可能是clojure- managed版本的问题。

when I macroexpand the code from these two question they come out the same so it seems likely that the problem is not with the contents of mysql_test.clj.

当我从这两个问题中对代码进行宏展开时,它们的结果是一样的,所以看起来问题不在于mysql_test.clj的内容。