Tutorial by Examples

Since Java 6, the recommended way to access an SQL-based database in Java is via the JDBC(Java DataBase Connectivity) API. This API comes in two packagages: java.sql and javax.sql. JDBC defines database interactions in terms of Connections and Drivers. A Driver interacts with the database, and pr...
Once we've gotten the Connection, we will mostly use it to create Statement objects. Statements represent a single SQL transaction; they are used to execute a query, and retrieve the results (if any). Let's look at some examples: public void useConnection() throws SQLException{ Connection ...
To connect using java.sql.DriverManager you need a JDBC url to connect to your database. JDBC urls are database specific, but they are all of the form jdbc:<subprotocol>:<subname> Where <subprotocol> identifies the driver or database (for example postgresql, mysql, firebirdsql,...
To connect to MySQL you need to use the MySQL Connector/J driver. You can download it from http://dev.mysql.com/downloads/connector/j/ or you can use Maven: <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version...
UCanAccess is a pure Java JDBC driver that allows us to read from and write to Access databases without using ODBC. It uses two other packages, Jackcess and HSQLDB, to perform these tasks. Once it has been set up*, we can work with data in .accdb and .mdb files using code like this: import java.sq...
Driver: 12c R1 11g R2 (Note: the driver is not included in Maven Central!) Driver class initialization: Class.forName("oracle.jdbc.driver.OracleDriver"); Connection URL Older format, with SID "jdbc:oracle:thin:@<hostname>:<port>:<SID>" Newer...

Page 1 of 1