Please enable JavaScript.
Coggle requires JavaScript to display documents.
JDBC (04- Reading Data (Calling Stored Procs ({call proc_name(?)}, use…
JDBC
04- Reading Data
ResultSet cursor
rs.next(), rs.getInt(), rs.getString() etc
scrollable resultset
rs.beforeFirst(), rs.first(), rs.last(), rs.absolute() etc
resultsets are not scrollable by default, set type in createStatement method
-
-
-
-
02- Getting Started
Whats JDBC?
-
part of JDK only, no external JARS required
-
JDBC alternatives
Spring JdbcTemplate, RIFE, Hibernate, JPA
The above libs uses JDBC under the hood, simplifies code
JDBC Drivers
-
Type 1, Type 2, Type 3, Type 4 drivers
MySQL connection
Download MySQL java drivers, add it to java project build path
USERNAME, PASSWORD, CONNECTION_STRING
Connection conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD)
-
05- Managing Data
Java beans
one java bean class for each table, singular name for the table as database tables might have plural name
create private property for each column field, generate public getters & setters for each property
-
-
Insert/update/delete
-
statement.executeUpdate() to update the data, it returns the primary key of the inserted row, to get it use get functions
-
ConnectionManager
connections take time, resources and memory, so avoid making several connections
-
-
01- Installations
-
-
create a database, tables, data, database users
03- Manage DB Resources
-
SQLException class
getErrorCode, getSQLState, getNextException, setNextException, iterator methods
Closable
ResultSet, Statement, Connection should be closed
Try with will close it all, so no need of boilerplate code
06- Using Metadata
Metadata helps you get database information like tables, columns, columns datatype etc