2017-08-07 61 views
-1

我是一个简单的数据库项目,作为我的数据库课程的一部分。我以前使用相同的语法从数据库读取,但现在它给我一个错误。来自MySQL数据库的Java读取错误

我想我在这里犯了一个愚蠢的错误。 :(

query = "SELECT d.id , d.img, d.score, d.rank , u.username , u.email , u.password " 
 
        + " FROM user AS u INNER JOIN userDetails AS d" 
 
        + " ON d.userId = u.id where u.id = ? "; 
 
statement = Database.conn.prepareStatement(query); 
 
System.out.println("Indicator.getUser_id() returns " + Indicator.getUser_id()); 
 
statement.setInt(1, Indicator.getUser_id()); // Indicator.getUser_id() returns 3 
 
rs = statement.executeQuery(query); 
 

 

 

 
Executing C:\Users\Sifat Ahmed\Documents\NetBeansProjects\OJ\dist\run1769679748\OJ.jar using platform C:\Program Files\Java\jdk1.8.0_131\jre/bin/java 
 
Successfully Connected.. 
 
3 
 
Indicator.getUser_id() returns 3 
 
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 '?' 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.ConnectionImpl.execSQL(ConnectionImpl.java:2738) 
 
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1617) 
 
at indicator.User.createUser(User.java:43) 
 
at UserProfile.UserprofileController.initialize(UserprofileController.java:48) 
 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) 
 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) 
 
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) 
 
at UserLogin.UserLoginPageController.login(UserLoginPageController.java:95) 
 
at UserLogin.UserLoginPageController.login_btnClicked(UserLoginPageController.java:57) 
 
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:54) 
 
at javafx.event.Event.fireEvent(Event.java:198) 
 
at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470) 
 
at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398) 
 
at javafx.scene.Scene$MouseHandler.process(Scene.java:3766) 
 
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$354(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$148(WinApplication.java:191) 
 
at java.lang.Thread.run(Thread.java:748)

+0

你是否发现它实际上发布了你正在发布的错误? –

+0

我添加了两个你可能错过的截图。 –

+0

请不要发布错误消息或堆栈痕迹的图片。相反,请在您的问题中包含完整的错误文本。 – avojak

回答

1

删除这已经是该语句定义的查询(与重载executeQuery方法常见的错误)

rs = statement.executeQuery(); 
+0

非常感谢。这对我来说太蠢了。 –

0

我觉得万阿英,蒋达清在这一行statement.setInt(1, Indicator.getUser_id());我猜Indicator.getUser_id()返回一个字符串,所以试试这个statement.setString("1", Indicator.getUser_id())

+0

public static int getUser_id(){ return user_id; } –