What is JDBC API?
The latest version of JDBC API is 4.1 (comes Java SE 7). The API contains two packages:
- java.sql: provides core API.
- javax.sql: provides additional API for server side database capabilities.
API specification for both the packages is available in the Java SE API documentation.
String driverClassName1 = “com.mysql.jdbc.Driver”;
String databaseURL1 = “jdbc:mysql://localhost:3306/test”;
String userName1 = “root”;
String password1 = “admin”;
try {
Class.forName(driverClassName1);
Connection conn = DriverManager.getConnection(databaseURL1, userName1, password1);
System.out.println(“Connected to database at ” + databaseURL1);
conn.close();
} catch (ClassNotFoundException cfe) {
System.out.println(“Database driver class could not be found”);
cfe.printStackTrace();
} catch (SQLException sqlex) {
System.out.println(“SQL ERROR”);
sqlex.printStackTrace();
}
Recent Comments