* JSP_MYSQL 연동
1. Class.forName
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=euckr";
// String url = "jdbc:mysql://127.0.0.1:3306/test";
try {
Class.forName("com.mysql.jdbc.Driver");
//Class.forName("org.gjt.mm.mysql.Driver");
con = DriverManager.getConnection(url,"root","s0111");
stmt= con.createStatement();
String sql="select * from tjdcref";
rs=stmt.executeQuery(sql);
while(rs.next()) {
debugPrint(rs.getString(3)+"<br>");
}
} catch(ClassNotFoundException e) {
debugPrint(e.toString());
return;
} catch(Exception e) {
System.out.println("MySQL Connection error!");
debugPrint(e.toString());
return;
}
2. DriverManager.registerDriver
String user="root";
String pass="s0111";
String dbURL="jdbc:mysql://localhost:3306/test";
Connection connection;
Statement stmt3=null;
ResultSet rs3=null;
String strsql="";
try{
DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
connection=DriverManager.getConnection(dbURL, user, pass);
debugPrint("Driver found! Connection Good!");
stmt3= connection.createStatement();
strsql="select * from tjdcref";
rs3=stmt3.executeQuery(strsql);
while(rs3.next()) {
debugPrint(rs3.getString(3));
}
}
catch(SQLException ex){
debugPrint("jdbc driver not founded!");
}
'IT' 카테고리의 다른 글
[스크랩] Visual C++ 2008 Feature Pack Sample 살펴보기 (0) | 2010.04.20 |
---|---|
[스크랩] powershell배치파일을 windows예약작업에 등록하는 방법 (0) | 2010.04.09 |
[스크랩] jsp 쿠키 사용하기 (0) | 2010.03.15 |
[스크랩] JSP 코드 작성 표준 양식 - 펌 (0) | 2010.03.15 |
[스크랩] java 특수문자 (0) | 2010.03.15 |