JDBC Flashcards
relational database
a database that is organized into tables, which consist of rows and columns
What do you have to know about SQL for the exam?
Pretty much nothing.
Just assume any SQL code that you see is valid.
Driver interface
Knows how to get a connection to the database
Connection interface
Knows how to communicate with the database
Statement interface
Knows how to run the SQL
ResultSet interface
Knows what was returned by a SELECT query
JDBC URL format
jdbc:database_name:connection_details
The first part is jdbc. The second part is the name of the vendor/ product. The third part varies by database, but it includes the location and name of the database. The location is either localhost or an IP address followed by an optional port.
How to create a Connection using DriverManager
DriverManager.getConnection(jdbc_url)
DriverManager.getConnection(
jdbc_url, “username”,
“password”);
How to create a Statement from a Connection called conn
conn. createStatement()
conn. (ResultSet, ResultSet)
What modes is a ResultSet in by default?
TYPE_FORWARD_ONLY and CONCUR_READ_ONLY
ResultSet.TYPE_FORWARD_ONLY
You can go through the data once in the order in which it was retrieved.
ResultSet.TYPE_SCROLL_INSENSITIVE
Allows you to go through the data in any order. You can go both forward and backward. You can even go to a specific spot in the data.
Note: there is another value TYPE_SCROLL_SENSITIVE that most databases don’t support.
ResultSet.CONCUR_READ_ONLY
It means that you can’t update the result set.
ResultSet.CONCUR_UPDATABLE
lets you modify the database through the ResultSet
What method do you use to execute a SQL statement given Statement stmt?
For UPDATE, DELETE, and INSERT:
stmt.executeUpdate(sql_statement);
Returns the number of rows that were inserted, deleted, or changed.
For SELECT:
stmt.executeQuery(sql_statement);
Returns a ResultSet
For general use:
stmt.execute(sql_statement)
Returns a boolean that indicates whether or not it is a ResultSet