-
728x90
CRUD
Create
Read
Update
Delete
DB: 계층형, 관계형, 객체형, 객체 관계형 존재
SQL
JDBC: 자바 코드에서 SQL문을 작성하여 코드를 작성
ORM(Object Relational Mapping): 자동으로 자바 코드가 SQL문으로 변경하게 만드는 기술
-> Hibernate, JPA
MySqld 초기화
Mysqld 실행
Mysql 실행 -> 패스워드 입력
패스워드 변경
초기화 후 패스워드는 C:\mysql-8.0.30-winx64\data의 err로 끝나는 파일에 있음
DB자바로 실행
String dbUser="root";String dbPassword="PW";String dbUrl="jdbc:mysql://localhost:3306/ooo";//mysql 서버IP: 서버Port / DB 이름DB 연결
Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);public class MysqlConn {public void dbconn(){String dbUser = "root";String dbPassword = "PW";String dbUrl = "jdbc:mysql://localhost:3306/ooo";//mysql :// 서버IP : 서버Port / DB 이름Connection conn = null;Statement stmt=null;ResultSet rs=null;try {Class.forName("com.mysql.cj.jdbc.Driver");conn = DriverManager.getConnection(dbUrl, dbUser,dbPassword);stmt=conn.createStatement();rs=stmt.executeQuery("Select 1");
if(rs.next()){int num=rs.getInt(1);System.out.println(num);}// SQL 쿼리문 실행
} catch (Exception e) {throw new RuntimeException(e);}}}dbconn test
class ConnTestThread extends Thread{
public void run() {MysqlConn mysqlConn = new MysqlConn();mysqlConn.dbconn();}}public class ConnTest {public static void main(String[] args) {for(int i=0;i<10;i++){Runnable r = new ConnTestThread();Thread t = new Thread(r);t.start();}}}Hikariimport java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;
import com.zaxxer.hikari.HikariConfig;import com.zaxxer.hikari.HikariDataSource;
public class HikariCPEx {public void dbconn() {String configFile = "src/main/resources/db.properties";HikariConfig cfg = new HikariConfig(configFile);HikariDataSource ds = new HikariDataSource(cfg);
Connection conn = null;PreparedStatement pst = null;ResultSet rs= null;
try{conn = ds.getConnection();pst=conn.prepareStatement("SELECT 10000");rs=pst.executeQuery();while(rs.next()){System.out.println(rs.getInt(1));}}catch(Exception e){
}}}Hikari test
class HikariConnTestThread extends Thread{
public void run() {HikariCPEx hikariCPEx = new HikariCPEx();hikariCPEx.dbconn();}}public class ConnTest {public static void main(String[] args) {for(int i=0;i<10;i++){Runnable r = new HikariConnTestThread();Thread t = new Thread(r);t.start();}}}728x90반응형'공부' 카테고리의 다른 글
네이버 항공권 크롤링 - 파이썬 (0) 2022.08.09 클라이언트 서버 채팅 (0) 2022.07.29 kafka (0) 2022.07.28 HashMap (0) 2022.07.28 서버 통신 (0) 2022.07.28