Clojure MySQL syntax error exception ("[...] next to '????????????????' [...]")

I am having problems with anything with clojure.contrib.sql other than establishing a connection.

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

When I try to "select * from clj_table" I get "com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: you have an error in the SQL syntax, check the manual that matches the version of your MySQL server, use about '?????? for the correct syntax ??????????? ' on line 1 ".

What am I doing wrong?

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

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
3

Sun JDK6 GIJ.

"com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: ". , .

"-Djava.net.preferIPv4Stack = true", .

!

+2

, Java. , .

, "useJvmCharsetConverters = true" .

+1

the code looks very similar to the (supposedly working) code in This question is
possibly a problem with the clojure -contrib version.

when I macro express the code from these two questions, they come out the same way, so it seems likely that the problem is not related to the contents of mysql_test.clj.

0
source

Source: https://habr.com/ru/post/1730631/


All Articles