|
|
Once you have your connection, you can get a Statement to make
database calls.
-
To get a statement,
Statement stmt = conn.createStatement();
-
Then make your SQL string. This should be exactly like SQL you might
enter directly into the database.
String updateStudents = "UPDATE students SET CollegeID = 32 where
CollegeID = 30 AND Major = "IT";
-
And use the appropriate Statement method to run.
-
In this case, we'll use executeUpdate(), which returns the number of rows
modified.
int updated = stmt.executeUpdate(updateStudents);
-
If your statement includes the words INSERT, UPDATE, DELETE, DROP TABLE
or CREATE TABLE, you should use executeUpdate().
-
Queries with SELECT are a bit more complicated, though.
SELECT queries and ResultSets
|