JDBC Driver

  • Oracle
  • Driver Class: oracle.jdbc.driver.OracleDriver;
  • Driver Jar: ojdbc8.jar
  • URL : jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"
  • MySQL
  • Driver Class: com.mysql.cj.jdbc.Driver
  • Driver Jar: mysql-connector-java-8.0.11.jar
  • URL:jdbc:mysql://localhost:3306/Jdbc10am?useSSL=false
  • PostgreSQL
  • Driver Class: org.postgresql.Driver
  • Driver Jar: postgresql-42.xjar
  • URL: jdbc:jdbc:postgresql://localhost:5432/rajeshdb


1. Load the Driver :
Class.forName("oracle.jdbc.driver.OracleDriver");

2. Connection :
String url = "jdbc:mysql://localhost:3306/yourDatabase";
Connection conn = DriverManager.getConnection(url, "yourUsername", "yourPassword");

3.Create Statement & Perform CRUD:
Statement stmt = conn.createStatement();

4.Create (Insert)  :
String insertSQL = "INSERT INTO yourTable (column1, column2) VALUES ('value1', 'value2')";
int rowsInserted = stmt.executeUpdate(insertSQL);

5.Update :
String updateSQL = "UPDATE yourTable SET column1 = 'newValue' WHERE condition";
int rowsUpdated = stmt.executeUpdate(updateSQL);
6.Delete :
String deleteSQL = "DELETE FROM yourTable WHERE condition";
int rowsDeleted = stmt.executeUpdate(deleteSQL);

7.Select :
String selectSQL = "SELECT * FROM yourTable";
ResultSet rs = stmt.executeQuery(selectSQL);
while (rs.next()) {
    // Process each row, e.g.:
    System.out.println("Column Value: " + rs.getString("column1"));
}
Cleanup Resources:
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();        

JDBC is a powerful tool that bridges your Java applications with databases, enabling efficient data manipulation and management. Mastering these steps with Oracle, MySQL, and PostgreSQL can significantly enhance your development workflow.

Feel free to share your experiences and tips with JDBC in the comments!

要查看或添加评论,请登录

社区洞察

其他会员也浏览了