| | |
Java SQL update syntax
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
try {
//1.Load the database Driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//2.Make a connection to the database
Connection conn = DriverManager.getConnection(
"jdbc:odbc:MyDataSource");
Statement stmt = conn.createStatement();
String x = jTextField1.getText().toString();
String sqll ="UPDATE Patient_Comp SET taken='Taken'WHERE ID="+x ;
ResultSet rs = stmt.executeQuery(sqll);This is what i wrote to update a instance of a column, but i am getting exceptions.. i am not sure if executeQuery
is the correct attribute. will some one please provide me with the working code ..
Last edited by localp; Jun 8th, 2009 at 3:28 pm.
Local P ...
•
•
•
•
Well, the first hint would be the exception itself, which you did not specify here.
I would recommend using executeUpdate() which returns the number of rows affected instead of executeQuery(), which return a result set.
Anyway apart from using executeUpdate maybe you should leave a space between 'Taken' and WHERE:
String sqll ="UPDATE Patient_Comp SET taken='Taken'WHERE ID="+x ;
Check out my New Bike at my Public Profile at the "About Me" tab
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
Java Syntax (Toggle Plain Text)
java.sql.SQLException: No ResultSet was produced at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:259) at shanesmed.DocDisplay.jButton2_actionPerformed(DocDisplay.java:150) at shanesmed.DocDisplay_jButton2_actionAdapter.actionPerformed(DocDisplay.java:179) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234) at java.awt.Component.processMouseEvent(Component.java:5488) at javax.swing.JComponent.processMouseEvent(JComponent.java:3093) at java.awt.Component.processEvent(Component.java:5253) at java.awt.Container.processEvent(Container.java:1966) at java.awt.Component.dispatchEventImpl(Component.java:3955) at java.awt.Container.dispatchEventImpl(Container.java:2024) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822) at java.awt.Container.dispatchEventImpl(Container.java:2010) at java.awt.Window.dispatchEventImpl(Window.java:1774) at java.awt.Component.dispatchEvent(Component.java:3803) at java.awt.EventQueue.dispatchEvent(EventQueue.java:463) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149) at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
This is the exception that i got
Local P ...
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
•
•
•
•
Well, the first hint would be the exception itself, which you did not specify here.
I would recommend using executeUpdate() which returns the number of rows affected instead of executeQuery(), which return a result set.
Then how can i update ?? what will be the java code for update
Local P ...
•
•
Join Date: Apr 2008
Posts: 102
Reputation:
Solved Threads: 2
Java Syntax (Toggle Plain Text)
String sqll ="UPDATE Patient_Comp SET taken='Taken' WHERE ID="+x ; int rs = stmt.executeUpdate(sqll);
thanks guys it worked !!!
Local P ...
![]() |
Similar Threads
- Need help with SQL update query (MS SQL)
- VB 2008 Express Compact SQL UPDATE query error (VB.NET)
- help in java and sql server 2005 interfacing (Java)
- Problem with SQL UPDATE syntax in vb 2008 (VB.NET)
- java.sql.SQLException: Invalid column index (Java)
- Error java.sql.SQLException: [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle (Java)
- not finding java.sql package (Java)
- tool for converting java/sql codes to asp.net/sqol2000 (Java)
Other Threads in the Java Forum
- Previous Thread: Sending files in socket problem///
- Next Thread: Contd from Mouse over
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads time tree unlimited utility webservices windows






