Steps to use JDBC in java applications as follows
- Load the JDBC driver.
- Define the connection URL.
- Establish the connection.
- Create a statement object.
- Execute a query or update.
- Process the results.
- Close the connection.
Class.forName("driveClassName");
Connection con = DriverManager.getConnection(
"jdbc:driveName:databaseName", "login", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Table");
while (rs.next()) {
int a = rs.getInt("column1");
String b = rs.getString("column2");
float c = rs.getFloat("column3");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
// close the connection
}
No comments:
Post a Comment