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 ..

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.

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.

I thought that you cannot use executeQuery for "insert", "update", "delete" queries.
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 ;
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

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

As I already posted, and so did javaAddict:
use executeUpdate().

String sqll ="UPDATE Patient_Comp SET taken='Taken' WHERE ID="+x ;
            int rs = stmt.executeUpdate(sqll);

thanks guys it worked !!!

BTW, consider using prepared statements / parameterized queries instead of creating queries on fly using string concatenation to avoid SQL Injection.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.