You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.4 KiB
40 lines
1.4 KiB
package org.poopki.duckdns.user_db.DB; |
|
|
|
import java.sql.*; |
|
|
|
|
|
public class DBConnect { |
|
private static final String DB_DRIVER_CLASS = "org.mariadb.jdbc.Driver"; |
|
private static final String DB_URL = "jdbc:mariadb://poopki.duckdns.org:3307/"; |
|
private static final String DB_USERNAME = "mc_dev"; |
|
private static final String DB_PASSWORD = "!Rkdalsrn1027"; |
|
|
|
public static Connection connectDB(){ |
|
Connection conn = null; |
|
Statement stmt = null; |
|
try { |
|
Class.forName("org.mariadb.jdbc.Driver"); |
|
|
|
conn = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD); |
|
System.out.println("Connection success"); |
|
stmt = conn.createStatement(); |
|
StringBuilder sb = new StringBuilder(); |
|
String sql = sb.append("create table if not exists student(") |
|
.append("id int,") |
|
.append("name varchar(20),") |
|
.append("grade int") |
|
.append(");").toString(); |
|
stmt.execute(sql); |
|
} |
|
catch (ClassNotFoundException e) { |
|
e.printStackTrace(); |
|
} |
|
catch (SQLException e) { |
|
// TODO Auto-generated catch block |
|
System.err.println("에러 내용 :" + e.getMessage()); |
|
System.out.println("DB Connection fail"); |
|
} |
|
return conn; |
|
} |
|
|
|
}
|
|
|