- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在查询运行时查看它,但我得到的只是:
INSERT INTO tblusers (first_name, middle_initial, last_name, username, password, privilege) VALUES (?,?,?,?,?,?)
我看不出我创建的插入代码有什么问题,并且该错误对我没有多大帮助。这是我的代码供引用:
String query = ("INSERT INTO tblusers (first_name, middle_initial, last_name, username, password, privilege)"
+ " VALUES (?,?,?,?,?,?)");
stmt = conn.prepareStatement(query);
stmt.setObject(1, txtFn.getText());
stmt.setObject(2, txtMi.getText());
stmt.setObject(3, txtLn.getText());
stmt.setObject(4, txtUser.getText());
stmt.setObject(5, txtPass.getText());
stmt.setString(6, "'student'");
System.out.println(query);
stmt.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
ResultSet rs = stmt.getGeneratedKeys();
Integer result =- 1;
if (rs.next()) {
result = rs.getInt(1);
}
String query2 = ("INSERT INTO tblcourseinfo (user_id, course_id, school_id) VALUES (?,?,?)");
stmt.setObject(1, result);
stmt.setObject(2, cmbCourse.getId());
stmt.setObject(3, cmbSchool.getId());
stmt.executeUpdate(query2);
如何消除该错误,谁能一目了然地告诉我插入语句出了什么问题?
这是堆栈跟踪:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'first_name, middle_initial, last_name, username, password, privilege VALUES (?,?' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2788)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1816)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1904)
at elibraryserver.NewStudentController.registerButtonAction(NewStudentController.java:171)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._enterNestedEventLoopImpl(Native Method)
at com.sun.glass.ui.win.WinApplication._enterNestedEventLoop(WinApplication.java:204)
at com.sun.glass.ui.Application.enterNestedEventLoop(Application.java:511)
at com.sun.glass.ui.EventLoop.enter(EventLoop.java:107)
at com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:583)
at javafx.stage.Stage.showAndWait(Stage.java:474)
at elibraryserver.NewStudentController.initRegister(NewStudentController.java:152)
at elibraryserver.serverController.addStudentButtonAction(serverController.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.control.MenuItem.fire(MenuItem.java:462)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.doSelect(ContextMenuContent.java:1405)
at com.sun.javafx.scene.control.skin.ContextMenuContent$MenuItemContainer.lambda$createChildren$343(ContextMenuContent.java:1358)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
最佳答案
行 stmt.executeUpdate(query, Statement.RETURN_GENERATED_KEYS);
是错误的。它不适用于 PreparedStatement
,因为它执行查询时没有添加参数。
您还需要另一个 PreparedStatement
来进行第二个查询,并且最好使用 setString()
或 setInt()
而不是 setObject( )
。由于您已经使用了 PreparedStatement
,因此不需要将字符串 student
嵌入单引号中,除非您需要它们。
例如:
String query = ("INSERT INTO tblusers (first_name, middle_initial, last_name, username, password, privilege)"
+ " VALUES (?,?,?,?,?,?)");
PreparedStatement ps1 = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
ps1.setString(1, txtFn.getText());
ps1.setString(2, txtMi.getText());
ps1.setString(3, txtLn.getText());
ps1.setString(4, txtUser.getText());
ps1.setString(5, txtPass.getText());
ps1.setString(6, "student");
ps1.executeUpdate();
ResultSet rs = ps1.getGeneratedKeys();
Integer result =- 1;
if (rs.next()) {
result = rs.getInt(1);
}
String query2 = "INSERT INTO tblcourseinfo (user_id, course_id, school_id) VALUES (?,?,?)";
PreparedStatement ps2 = con.prepareStatement(query2);
ps2.setInt(1, result);
ps2.setInt(2, cmbCourse.getId());
ps2.setInt(3, cmbSchool.getId());
ps2.executeUpdate();
关于java - 向数据库插入数据但出现 MySQLSyntaxErrorException : You have an error in your SQL syntax 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47647612/
我不知道为什么我得到这些结果。 ++ +add +syntax error 2 ++ +add +syntax error 4 ++是我的输入,并且lex会回显每个字符,并且每当获得+时yacc打印就
这个问题在这里已经有了答案: Syntax error on print with Python 3 [duplicate] (3 个回答) 关闭8年前。 为什么 Python 在第 9 行的简单 p
我有一个非常简单的 SQL 语句 SELECT * FROM Table; 但是,我的查询引擎返回一个语法错误。为什么? 错误详情: An unhandled exception of type 'S
我正在尝试编写一些代码来模拟具有两个三态缓冲器和VHDL中的上拉电阻的电路。下面是我的代码: library ieee; use ieee.std_logic_1164.all; entity Pul
我已经编写了这个mergesort实现,如果将除法功能放在mergesort函数之外,效果很好。但是,当我尝试使除法成为mergesort的内部函数时,遇到语法错误。 我知道,对此必须有一些非常简单的
(我是 Linux 和 Vim 新手,我正在尝试学习 Vim,但我遇到了一些无法解决的问题) 我安装的 Linux (Ubuntu 8.04) 无法使用 Vim 7.1.138 进行更新。 我的 vi
这个错误让我抓狂,我需要帮助。 Syntax Error: Token '{' invalid key at column 2 of the expression [{{ field }}.$erro
原标题是“特定于语言的配色方案防止较简单的配色方案为某些特定于语言的标签着色” 我正在使用 gVim 7.3(在 Ubuntu 12.04 Arch x86/64 上,这很重要)。 更新(2013-0
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
我正在编写某种“编译器”:它读取游戏的描述(包括房间,角色,事物等)。将其视为冒险类游戏的视觉版本,但存在很多简单问题。 当我运行“编译器”时,输入中出现语法错误,我不知道为什么。这是我的yacc输入
我正在构建一个示例应用程序(请参阅plunk https://plnkr.co/edit/vDXcSPrOjw5qvBQKcYvw?p=preview)。 var myA
语法错误文件: 我想知道在哪里可以看到确切的错误信息。vivado中没有任何提示。 谢谢! 最佳答案 通常,您可以检查屏幕底部的消息选项卡。无论如何,Vivado并不是特别擅长告诉您代码有什么问题(我
您好,这是我的迷你编程语言的野牛语法文件: %{ #include #include #include #include "projectbison.tab.h" void y
Fmax我的代码中的参数报告为:No Paths to report .因此,我试图使用 set_input_delay 设置与定义时钟的输入信号关系。 .但是,错误报告指出: Verilog HDL
我正在开发一个使用 Twig 的 Symfony2 项目,文件类型为 myfile.html.twig。 Vim 不会自动检测语法突出显示,因此不应用任何语法。打开文件后,我可以使用 :set syn
这是一个相对简单的代码,用于“在半径为2个单位的圆象限上使用中坐标规则评估pi”。 main.alg BEGIN REAL x, y, sumy, pi; INT n := lowerlimit, p
我对我的简单插入所产生的错误感到非常困惑。我已经通过不同的检查器多次检查了语法并搜索了类似的问题,但没有找到解决方案。 错误看起来像这样: 'SQLSTATE[42000]: Syntax error
我尝试了以下代码: with x as 1: y = 1 with z as 1: w = 1 编译器报告了 SyntaxError:语法无效。有什么问题? [已编辑:]我想做的是:
我在 Webstorm 中使用 vue 框架,使用 ES6 语法。 我已经安装了 vue-for-idea 插件,如果我使用纯 ES5 语法,一切都会很顺利。 但是代码的ES6部分似乎还没有被识别,并
我将我认为有用的代码示例作为文本文件保存在我的计算机上。我将它们存储为 txt 文件而不是编写它们的语言,以便它们将在 Notepad++ 中打开而不是在编辑器中打开(即我不希望我的 c++ 示例在
我是一名优秀的程序员,十分优秀!