jsp mssql 연동 방법

JSP 2012/11/13 17:19

SQL Server jdbc 드라이버 다운로드 : http://www.microsoft.com/ko-kr/download/details.aspx?id=11774

jsp에서는 mssql을 연동하기 위해서는 SQL Server jdbc 드라이버가 필요하며,
라이브러리 업로드 위치에 올려놓으면 준비는 끝난다.

mssqlcon.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>

<%

Connection conn = null;
Statement stmt =null;
ResultSet rs = null;
try{
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    conn =  DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=DATABASENAME","ID","PASSWORD");
    stmt = conn.createStatement();
    rs = stmt.executeQuery("select * from test");
    out.println("success");
} catch(Exception e) {
        out.println(e);
}
%>
2012/11/13 17:19 2012/11/13 17:19

jsp jstl 적용방법

JSP 2012/10/26 11:48
http://theeye.pe.kr/entry/simple-example-of-using-jstl-core-tag-library
2012/10/26 11:48 2012/10/26 11:48

<%response.setHeader("Content-Language", "jp");%>
2012/10/26 09:54 2012/10/26 09:54
1. JNDI을 이용하지 않는 연결 소스

<html>
<head>
<%@ page import="java.sql.*, javax.sql.*, java.io.*" %>
</head>
<body>
<h1>JDBC Test</h1>

<%
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@teste.com:1521:orcl", "아이디" , "패스워드");

String query = "select * from test where rownum <= ?";
//String query="INSERT INTO test  (t1, t2, t3, t4, t5)   VALUES   (LPAD(SEQ_test.NEXTVAL, 1, '0'), ?, ?,TO_DATE(SYSDATE,'YYYY/MM/DD'),TO_DATE(SYSDATE,'YYYY/MM/DD'))";

PreparedStatement pstmt = conn.prepareStatement(query);
pstmt.setInt(1, 3);

//pstmt.setString(1, "Y");
//pstmt.setString(2, "aa");

System.out.println(query);
ResultSet rset = pstmt.executeQuery();
//int rset = pstmt.executeUpdate();
while (rset.next()) {
out.println(rset.getString("column"));
}
rset.close();
pstmt.close();
conn.close();
%>
</body>
</html>

2. JNDI을 이용한 연결 소스

<html>
<head>
<%@ page
import="java.sql.*,
javax.sql.*,
java.io.*,
javax.naming.InitialContext,
javax.naming.Context" %>
</head>
<body>
<h1>JDBC Test</h1>

<%
InitialContext initCtx = new InitialContext();
DataSource ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/oracle");
Connection conn = ds.getConnection();

String query = "select * from tab";

PreparedStatement pstmt = conn.prepareStatement(query);

System.out.println(query);
ResultSet rset = pstmt.executeQuery();

while (rset.next()) {
out.println(rset.getString("tname"));
out.println("<br>");
}
rset.close();
pstmt.close();
conn.close();
%>
</body>
</html>
2012/10/22 16:20 2012/10/22 16:20
http://dexcore.tistory.com/500
2012/10/02 09:45 2012/10/02 09:45

Hibernate 프레임워크

JSP 2012/08/06 09:21
http://www.javajigi.net/display/FRAMEWORK/Hibernate+Getting+Started
2012/08/06 09:21 2012/08/06 09:21

컴파일한 클래스파일은 WEB-INF/classes/ 디렉토리 하위에 위치.
1. testclass.java

package sample;

public class testclass{

public String name="";

public String getTest(){
return name;
}
}


2. test.jsp
<%@ page contentType="text/html; charset=euc-kr" import="sample.testclass" %>


<%
testclass test1 = new testclass();
test1.name = "test";

out.println(test1.getTest());

%>
2012/05/16 18:45 2012/05/16 18:45
참고 URL : http://yoontaesub.egloos.com/1833116
2012/05/16 15:25 2012/05/16 15:25

1. 페이지 인코딩 설정.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

2. server.xml에 Connector 설정에 URIEncoding="UTF-8" 추가
<Connector port="8071"
               enableLookups="false" protocol="AJP/1.3" URIEncoding="UTF-8"  />

3. jsp 페이지 및 servlet에서 request.getParameter를 호출하기전에 UTF-8로 지정.
request.setCharacterEncoding("UTF-8");

2012/05/03 20:35 2012/05/03 20:35

jsp pgsql 연결방법

JSP 2012/02/08 13:38
http://blog.naver.com/PostView.nhn?blogId=kletgdgo&logNo=90102298547&categoryNo=19&viewDate=&currentPage=1&listtype=0
2012/02/08 13:38 2012/02/08 13:38