I'm using database, created with microsoft access. I have there three columns (username, password, already).
You probably know what username and password mean, and that already has two options (yes/no) it means that user already done this job(answer the quiz). So, here is my sql :
I have here two queries. One check if user is on the database, and if yes, I want to check if he doesn't already answered the quiz. I'm newbie in sql so I want to ask, what's wrong with that second sql? Because first time I run the program without another checking and it worked perfectly. When I added second if with another sql it shows this erro:
You probably know what username and password mean, and that already has two options (yes/no) it means that user already done this job(answer the quiz). So, here is my sql :
vardas = vartotojoVardas.getText().trim(); slaptaz = slaptazodis.getText().trim(); String sql = "select Username,Password from Table1 where Username = '"+vardas+"'and Password = '"+slaptaz+"'"; String sql2 = "select Already, from Table1 where Username = '"+vardas+"'and Password = '"+slaptaz+"'"; rt = st.executeQuery(sql); int count = 0; while(rt.next()){ count++; } rt = null; if(count == 1){ System.out.println("Connected"); rt = st.executeQuery(sql2); if(rt.next() == true){ System.out.println("Already completed"); } } else if(count == 0) System.out.println("Nera tokio vartotojo"); }catch(Exception e){ e.printStackTrace(); }
I have here two queries. One check if user is on the database, and if yes, I want to check if he doesn't already answered the quiz. I'm newbie in sql so I want to ask, what's wrong with that second sql? Because first time I run the program without another checking and it worked perfectly. When I added second if with another sql it shows this erro:
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] The table 'Table1' is already opened exclusively by another user, or it is already open through the user interface and cannot be manipulated programmatically. at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source) at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source) at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(Unknown Source) at kurybinis.PrisijungimoLangas.actionPerformed(PrisijungimoLangas.java:59) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$200(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source)