运行下面的 sql 语句 总是说 query 出错
use employees;
set autocommit=0;
begin;
SELECT * from employees where emp_no=10002;
commit;
1
kanilu OP 喔,对了,上面的 employees 是一个数据库,里面有一个表也叫 employees
|
2
kanilu OP 顶顶顶
|
3
zhusimaji 2017-07-09 23:11:14 +08:00 via iPhone
你要贴具体的错误信息....
|
4
kanilu OP @zhusimaji
SQL Error [1064] [42000]: 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 'SELECT * from employees where emp_no=10002; commit' at line 2 com.mysql.jdbc.exceptions.jdbc4.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 'SELECT * from employees where emp_no=10002; commit' at line 2 |
5
wdlth 2017-07-09 23:23:16 +08:00
开始事务是 begin transaction 吧,你输入的是 begin,就变成了 begin...end 流程控制了。
|
7
misaka19000 2017-07-10 00:19:27 +08:00 via Android
查询还有事务吗,第一次看到
|
8
11138 2017-07-10 00:28:33 +08:00
语法没有问题,问题在于你的用法有问题,你应该帖出相关的使用代码。
|
9
kiwi95 2017-07-10 00:36:05 +08:00 via Android
不知道你是要用 begin-end 控制块还是要用事物,按说你就一个 select 不需要用事物。
如果用 begin-end 你的写法不对,如果用事物应该用 start transaction,不是 begin transaction。 给你贴个文档 https://dev.mysql.com/doc/refman/5.7/en/begin-end.html |
10
kiwi95 2017-07-10 00:38:13 +08:00 via Android
既然是提问就多提供些信息,什么数据库,什么版本,具体报什么错,没人会去给你跑一下你的语句给你分析
|
11
11138 2017-07-10 00:39:52 +08:00
mysql> use employees;
Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> set autocommit=0; Query OK, 0 rows affected (0.00 sec) mysql> begin; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * from employees where emp_no=10002; +----+--------+ | id | emp_no | +----+--------+ | 1 | 10002 | +----+--------+ 1 row in set (0.00 sec) mysql> commit; Query OK, 0 rows affected (0.00 sec) mysql> use employees;set autocommit=0;begin;SELECT * from employees where emp_no=10002;commit; Database changed Query OK, 0 rows affected (0.00 sec) Query OK, 0 rows affected (0.00 sec) +----+--------+ | id | emp_no | +----+--------+ | 1 | 10002 | +----+--------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec) |
12
11138 2017-07-10 00:45:33 +08:00
https://dev.mysql.com/doc/refman/5.7/en/commit.html
START TRANSACTION or BEGIN start a new transaction. |
13
tomatoz 2017-07-10 04:37:34 +08:00
目测你把 commit 和其他语句写一起了。。
应该这样吧: …… statement.execute("blablabla"); conn.commit(); …… 另外查询操作也用不到事务 +1 |
14
heaton_nobu 2017-07-10 09:21:30 +08:00
这是在 commit 什么
|
15
leejanfin 2017-07-10 09:49:51 +08:00
单纯看这个 SQL 没发现什么问题
|