除了建立连接外,我在使用clojure.contrib.sql做任何事情时都遇到麻烦.
我有一个在localhost:3306上运行的mysqld,数据库名为clj_db.
密码为“ clj_pass”的用户“ clj_user” @“ localhost”可以访问该数据库.
当尝试“从clj_table中选择*”时,我得到一个“ com.MysqL.jdbc.exceptions.MySQLSyntaxErrorException:您的sql语法有误;请查看与您的MysqL服务器版本相对应的手册,以获取在’附近使用正确的语法” ????????????????’在第1行”.
我究竟做错了什么?
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
(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))
))
输出量
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
最佳答案
我已改用Sun的JDK6而不是GIJ.
原文链接:https://www.f2er.com/mysql/532037.html我收到“ com.MysqL.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败”.
我找到了this thread,这对我有很大帮助.
我添加了选项“ -Djava.net.preferIPv4Stack = true”,它现在可以正常工作.
谢谢大家!