JAVA DB connection method

A memo of the code to connect to the DB with JAVA

I do not fully understand it, so I will deepen my understanding from here.

public static void main(String[] args) {
		//DB connection
		Connection conn = null;
		PreparedStatement ps = null;
		try {
			Class.forName("org.postgresql.Driver");
			conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/DB name",
					"user",
					"password"
					);
			//Define a SQL statement
	        String sql = "INSERT INTO table name(●, ●, ●) values(?,?,?)";
			ps = conn.prepareStatement(sql);
			conn.close();
			System.out.println("Connected to DB.");
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("I failed.");
		}
		launch();
	}

Recommended Posts

JAVA DB connection method
Java method
java (method)
Try DB connection with Java
Java method
[Java] method
[Java] method
db connection notes
Java8 method reference
[Java] forEach method
DB connection method-JDBC
java8 method reference
[Java] Random method
[Java] split method
[Java] Connection with local DB (IntelliJ + SpringBoot)
Java learning 2 (learning calculation method)
Java learning memo (method)
About Java method binding
[Java ~ Method ~] Study memo (5)
About method splitting (Java)
Studying Java 8 (see method)
[Java] DB migration (Flyway)
Java programming (class method)
[Java] Basic method notes
Spring + MyBatis connection setting method
[Java] New Thread generation method (2)
[Template] MySQL connection with Java
Java GC method determination conditions
DB connection settings Spring-Boot application.properties
Java Silver Study Method Memo
Create a java method [Memo] [java11]
Java test code method collection
[Java Silver] About equals method
Connect to DB with Java
[Java] Timer processing implementation method
Check https connection in Java
[Java] Random number generation method (Random)
Java methods and method overloads
Spring Boot DB connection pool
Benefits of Java static method
[Java Silver] Array generation method
[Java] New Thread generation method (1)
Method
[Java] Object-oriented syntax --class method / argument
[PDO → DB connection with docker, PHP]
Automatic photo resizing method in Java
Java method list (memorial) (under construction)
[Java] How to use join method
Screen transition by Post method [Java]
[Java] Object-oriented syntax-class / field / method / scope
Java comparison using the compareTo () method
[Java beginner] == operator and equals method
Java
Try to extract java public method
HTTPS connection using tls1.2 in Java 6
Try using IBM Java method tracing
Java
[Java] Proxy setting method when starting Java
Java beginner design pattern (Factory Method pattern)
[Java] Processing time measurement method memo
Call the super method in Java