Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
Total
관리 메뉴

까먹지 말자! 자주 보자!

JSP BOARDER(3)_(ConnectionFactory .java) 본문

JSP

JSP BOARDER(3)_(ConnectionFactory .java)

Phonetographer 2016. 5. 24. 17:12

package board;

import java.sql.*;


public class ConnectionFactory {

private static ConnectionFactory connectionFactory = new ConnectionFactory();

private ConnectionFactory(){};

public static ConnectionFactory getDefaultFactory(){

if(connectionFactory == null){

connectionFactory = new ConnectionFactory();

}

return connectionFactory;

}

public static Connection createConnection(){

Connection connection = null;

try{

Class.forName("com.mysql.jdbc.Driver");

}catch(ClassNotFoundException cnfe){

System.out.println(cnfe);

}

String url = "jdbc:mysql://localhost:3306/noveljsp";

String user = "root";

String password = "123qwe123";

try {

connection = DriverManager.getConnection(url, user, password);

}catch(SQLException sqle){

System.out.println(sqle);

}

return connection;

}

}