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.