"Java DataBase Connectivity" is commonly used as the long form of the name. The seven standard steps for querying databases,
1. Load the JDBC driver. To load a driver, you specify the classname of the database driver in the Class.forName method. By doing so, you automatically created a driver instance and register it with the JDBC driver manager. -- triggered the class initialization.
Class.forName("oracle.jdbc.driver.OracleDriver");
2.Define the connection URL.
String host = "dbhost.yourcompany.com";
String dbName = "someName";
int port = 1234;
String oracleURL = "jdbc:oracle:thin:@" + host +
":" + port + ":" + dbName;
3.Establish the connection
Connection connection =
DriverManager.getConnection(oracleURL, username, password);
4.create a statement object
Statement statement = connection.createStatement();
5.execute a query or update
String query = "SELECT col1, col2, col3 FROM sometable";
ResultSet resultSet = statement.executeQuery(query);
6.process the result
7.close the connection
connection.close();
1. Load the JDBC driver. To load a driver, you specify the classname of the database driver in the Class.forName method. By doing so, you automatically created a driver instance and register it with the JDBC driver manager. -- triggered the class initialization.
Class.forName("oracle.jdbc.driver.OracleDriver");
2.Define the connection URL.
String host = "dbhost.yourcompany.com";
String dbName = "someName";
int port = 1234;
String oracleURL = "jdbc:oracle:thin:@" + host +
":" + port + ":" + dbName;
3.Establish the connection
Connection connection =
DriverManager.getConnection(oracleURL, username, password);
4.create a statement object
Statement statement = connection.createStatement();
5.execute a query or update
String query = "SELECT col1, col2, col3 FROM sometable";
ResultSet resultSet = statement.executeQuery(query);
6.process the result
7.close the connection
connection.close();
Comments
Post a Comment