The code snippet below helps illustrate a problem whose core cause I am trying to determine. The servlet will always open a connection and will create a statement for insertion(s) as shown; however ...it will not both do the insertion 'and' do the resultset....plus when inserting....it will insert only one row....it will not insert more than one....and having inserted one row....it will not open the result set and retrieve the table content. Only one function seems doable at a time....either insert(one row only) or retrieve the table. (The servlet does not abend).
Is this a function of Java (as written) or an issue with the sqliteJDBC class(es) I am using to include SQLite in the servlet ?
// Create a Statement object for the database connection, Statement stmt = conn.createStatement();
stmt.executeQuery("INSERT INTO name values('John', 'Dutcher', 0001)"); stmt.executeQuery("INSERT INTO name values('John', 'Dutcher', 0002)"); stmt.executeQuery("INSERT INTO name values('John', 'Dutcher', 0003)");
// Create a result set object for the statement ResultSet rs = stmt.executeQuery("SELECT * FROM name");
// Iterate the result set, printing each column
while (rs.next()) { String fn = rs.getString("first_name"); // Column 1 String ln = rs.getString("last_name"); // Column 2 String regnbr = rs.getString("regnbr"); // Column 3 out.println("First Name: "+fn+" Last Name: "+ln+" Registration #: "+regnbr); } // Close the result set rs.close(); // Close the connection conn.close();