카테고리 없음
[JSP] JDBC 연동 테스트 예제
너래쟁이
2018. 4. 30. 10:23
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 31 32 33 34 35 36 37 38 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ page 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=EUC-KR"> <title>JDBC 연동 테스트 예제</title> </head> <body> <% Connection conn=null; String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oracle:thin:@localhost:1521:orcl"; /* 반드시 이렇게 적어야함 */ Boolean connect = false; try{ Class.forName(driver); conn=DriverManager.getConnection(url,"scott","12341234"); //자신의 아이디와 비밀번호 connect = true; conn.close(); }catch(Exception e){ connect = false; e.printStackTrace(); } %> <% if(connect==true){%> 연결되었습니다. <%}else{ %> 연결에 실패하였습니다. <%}%> </body> </html> | cs |