I have 2 problems.
The INSERT queries below are not inserting records in the msAccess database. Can someone please explain why this is happenning and how I can fix it? I replaced single quotes with double quotes, but that doesnt help either.
In this code below, only 1 query gets executed, first one, rest are all skipped. I have to comment previous queries each time and recompile to execute the next one. Is there another way of doing this?
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn=null; conn= DriverManager.getConnection("jdbc:odbc:SS"); Statement s; s=conn.createStatement(); ResultSet rs; rs=s.executeQuery("drop table users"); rs=s.executeQuery("CREATE TABLE users ( id AUTOINCREMENT, username varchar(255) , pass varchar(255), PRIMARY KEY(id) ) "); rs=s.executeQuery(" insert into users (username, pass) values( 'name1', 'pass1') "); rs=s.executeQuery(" insert into users (username, pass) values( 'name2', 'pass2') "); } catch (SQLException ex) { ex.printStackTrace(); } catch(Exception ee) { ee.printStackTrace(); }
s.executeQuery("drop table users")will throw an exception if the table does not exists. You need to check whether the table exists before dropping it