Week 3 Flashcards
Put these in order
establish connection
close connection
create statement and its query
execute the statement
process results & metadata
establish connection
create statement and its query
execute the statement
process results & metadata
close connection
You import DriverManager into your class, getConnection() does what? What does it throw?
getConnection() creates instances of Connection, throws SQLException and SQLTimeoutException
T/F - getConnection() can be overloaded
True
What are the 3 String arguments used for getConnection?
Connection string (like a url), userid, password
note: connection string can specify options
jdbc:mysql
jdbc:oracle
jdbc:db2
jdbc:postgresql
jdbc:derby
jdbc:sqlserver
jdbc:sybase
What are these examples of?
Connection strings
Whats the problem with hard-coding our DB details like this? What is the solution?
“static final String DATABASE_URL =
“jdbc:mysql://localhost:3306/books”;
Connection connection = null;
connection = DriverManager.getConnection(
DATABASE_URL, “CST8288”, “CST8288”)
It creates maintenance issues later. Solution is to use a properties class.
Note: “CST8288” is used as the username and password in the last Q
Where is the JDBC driver located? What is the method you can use if it is not autoloaded?
mysql-connector-java.jar
Class.forName(“mysql-connector-java.jar”)
T/F - DataSource and DataManager are the same
False. DataSource uses JNDI (Java Naming & Directory Interface) to look up the data source info
DataSource requires a ____ serverq but we will not use DS in this course
JNDI
Once we have a Connection instance we use ____________() to obtain an instance of statement.
createStatement
Can createStatement be overloaded? How many arguments does the common form have?
Yes, 0 args
How does PreparedStatement differ from Statement?
It’s a very similar (object), it just uses parameters
Name this: Used to invoke a stored procedure in the DB
CallableStatement
Once you have an instance of Statement you can call methods on it to perform SQL actions. ________() is used for SELECT and returns ResultSet, ___________() is used for INSERT, UPDATE< DELETE
ExecuteQuery()
ExecuteUpdate()
Both ExecuteQuery() and ExecuteUpdate() are overloaded. In their simplest form they use a single _____ _______.
String argument.
How do you get ResultSetMetaData?
Use getMetaData() with an instance of ResultSet
With ResultSetMetaData, how did we obtain the count of columns, name of columns, and data type of columns?
Used getters on the instance of ResultSetMetaData
When using ResultSetMetaData, how do the column numbers differ from arrays?
Column numbers start at 1.
What method is used on a ResultSet instance to loop through each instance by row? Can hasNext() be used?
.next(). No.
When you use .next() on a ResultSet instance for the first time, which is the first row that will be selected? Why?
Row #1. The “cursor” is placed before the first row.
T/F - ResultSet can only retrieve rows going forward.
False, it can retrieve them in either direction.
T/F - When ResultSet is changed it can change the underlying database immediately
True. This must be set using createStatement()
Name this: Specifies that a ResultSet’s cursor can only move in the forward direction
TYPE_FORWARD_ONLY
Name this: Specifies that ResultSet’s cursor can scroll in either direction and that the changes made to the underlying data during ResultSet processing are not reflected in the ResultSet unless the program queries the DB again.
TYPE_SCROLL_INSENSITIVE
Specifies that a ResultSet’s cursor can scroll in either direction and that the changes made to teh underlying data during ResultSet processing are reflected immediately in the Result-Set
TYPE_SCROLL_SENSITIVE
Specifies that a ResultSet can’t be updated–changes so the ResultSet contents cannot be reflected in the DB with ResultSet’s update methods
CONCUR_READ_ONLY
Specifies that a ResultSet can be updated (i.e. changes so its contents can be reflected in the DB with ResultSet’s update methods)
CONCUR_UPDATABLE
When closing our connections for the DB objects, which order is used?
ResultSet, Statement, Connection (Opposite of allocation order)
What is the order that resources are allocated for DB objects?
Connection, Statement, ResultSet
The Properties class is a subclass of ________, it stores a key along with a value (both are limited to type ______)
HashTable, String
With the Properties class how can I get and set? How can I read from a file? How can I write to a file?
getProperty(), setProperty()
load()
list()
What do we store in the Properties class?
JDBC connetion string, userid, pass