[JAVA] db connection notes

DB connection memo (roughly written)


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


Connection con;
preparedStatment pstmt;
ResultSet ts;

//1.Connect with DB

con = DriverManager.getConnection(
            "jdbc:mysql://(DB address)",
            "(sqlid)",
            "(sqlpassword)"
        );

//2.Interact with db
pstmt = don.preparedStatement (sql statement);

//3.Execution of select statement and substitution of result
rs.pstmt.executeQuery();

//4.View results
while(rs.next()){

}catcg(SQLException e){
e.printStackTrace();
}fainally{
DB close process
}


Recommended Posts

db connection notes
DB connection method-JDBC
JAVA DB connection method
Try DB connection with Java
Spring Boot DB connection pool
[PDO → DB connection with docker, PHP]
JDBC connection with MySQL 8.x * Notes *
JUnit 4 notes
java notes
[Java] Connection with local DB (IntelliJ + SpringBoot)
synchronized notes
Understand how to share Spring DB connection (DB transaction)