- MY SQL
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>DB Connection Test</title> </head> <body> <% String DB_URL = "jdbc:mysql://아이피:3306/데이터베이스"; String DB_USER = "이름"; String DB_PASSWORD= "암호";
Connection conn; Statement stmt;
try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD); stmt = conn.createStatement(); conn.close(); out.println("MySql jdbc test: connect ok!!"); } catch(Exception e) { out.println(e.getMessage()); } %> </body> </html> |
- ORACLE
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>DB Connection Test</title> </head> <body> <% String DB_URL = "jdbc:oracle:thin:@아이피:1521:데이터베이스"; String DB_USER = "아이디"; String DB_PASSWORD= "비번";
Connection conn; Statement stmt;
try { Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD); stmt = conn.createStatement(); conn.close(); out.println("Oracle jdbc test: connect ok!!"); } catch(Exception e) { out.println(e.getMessage()); } %> </body> </html> |
- MSSQL
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>DB Connection Test</title> </head> <body> <% String DB_URL = "jdbc:sqlserver://아이피:1433;DataBaseName=데이터베이스명"; String DB_USER = "아이디"; String DB_PASSWORD= "비밀번호";
Connection conn; Statement stmt;
try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD); stmt = conn.createStatement(); conn.close(); out.println("MsSql jdbc test: connect ok!!"); } catch(Exception e) { out.println("[ERROR] "+e.getMessage()); } %> </body> </html> |
MSSQL 에서 위 빨간 부분은 sql 버전에 따라 jdbc:microsoft:sqlserver: 이렇게 사용할수도 있음. 테스트 완료~!