[英]Importing a sql dump to Eclipse
I have imported a dumped sql file from MySQl Workbench, but when I try to run in Eclipse I keep getting this error message. 我已经从MySQl Workbench导入了转储的sql文件,但是当我尝试在Eclipse中运行时,我一直收到此错误消息。
SQLException: You have an error in your SQL syntax; SQLException:您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
检查与您的MySQL服务器版本相对应的手册,以在'SET @OLD_CHARACTER_SET_RESULTS = @@ CHARACTER_SET_RESULTS /附近使用正确的语法。 / !40101 SET @OLD_COL' at line 8
/ !40101 SET @OLD_COL'在第8行
But when I copy the same information into MySQL it creates the schema and everything works fine. 但是,当我将相同的信息复制到MySQL时,它会创建模式,并且一切正常。 What am I doing wrong?
我究竟做错了什么?
Here is my java code: http://pastebin.com/B1RVMYUd 这是我的Java代码: http : //pastebin.com/B1RVMYUd
And if you need it here is the dumpfile: http://pastebin.com/RWpG0BEX 如果需要的话,这里是转储文件: http : //pastebin.com/RWpG0BEX
您好,最好在mysql语句的查询中上传转储
You execute the whole contents of the dump as a single SQL statement. 您可以将转储的全部内容作为单个SQL语句执行。 Try splitting the file contents (your
sql
String) using ;
尝试使用
;
分割文件内容(您的sql
字符串) ;
as the delimiter, and execute each statement separately. 作为分隔符,并分别执行每个语句。
(As an aside, it's good practice to put the calls to statement.close
/ conn.close
in a finally
clause, to make sure that the resources are always released.) (
conn.close
一句,优良作法是将对statement.close
/ conn.close
的调用放在finally
子句中,以确保始终释放资源。)
I'm a beginner, so my comments may not be the most clear or accurate, nor my code the most clear, concise, correct, etc. With that out of the way, here are a few things: 我是一个初学者,所以我的评论可能不是最清晰或最准确的,也不是我的代码最清晰,简明,正确的等。顺便说一句,这里有几件事:
1) You can't use executeQuery(sql) method to create. 1)您不能使用executeQuery(sql)方法创建。 So use one of the other options.
因此,请使用其他选项之一。 In my experiments, I used:
在实验中,我使用了:
sqlDumpArray = sqlDump.split(";");
for (int i = 0; i < sqlDumpArray.length; i++) {
System.out.println("\nsqlDumpArray[" + i + "] is: " + sqlDumpArray[i]); // To see what's in the array.
}
for (int j = 1; j < sqlDumpArray.length -1; j++) { // Ugly hack because sqlDumpArray[0] and sqlDumpArray.length-1 are problematic in this alpha version of code.
try {
Statement statement = conn.createStatement();
statement.addBatch(sqlDumpArray[j]);
statement.executeBatch(); // Maybe could move this out of the for-loop.
}
Regarding the SQL file: 关于SQL文件:
1) Strip out the comments. 1)删除注释。 2) Put a semicolon as the first character of the file (ie, row 1, column 1).
2)将分号作为文件的第一个字符(即,第1行,第1列)。
I did that and it works. 我做到了,而且有效。 Let me know if you want my complete code and I'll post it.
如果您需要我的完整代码,请告诉我,我将其发布。
Cheers, Chris 克里斯,干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.