[MSSQL]

// 2000 버전(삼총사버전)
Class.forName("com.microsoft.jdbc.sqlserver.jdbc.SQLServerDriver");
// 2005 버전(sqljdbc.jar)
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

String dbURL = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=project";
String dbUser = "sa";
String dbPassword = "pwd";

Connection conn = null;
try {
    conn = DriverManager.getConnection(dbURL, dbUser, dbPassword);
} catch (SQLException e) {
    e.printStackTrace();
    out.println("e: " + e);
}




JAR설명


 

sqljdbc.jar 클래스 라이브러리는 JDBC 3.0을 지원합니다.

sqljdbc.jar 클래스 라이브러리에는 JRE(Java Runtime Environment) 버전 5.0이 필요합니다. JRE 6.0에서 sqljdbc.jar을 사용하면 데이터베이스에 연결할 때 예외가 발생합니다.

ms378422.note(ko-kr,SQL.105).gif참고:
JDBC 드라이버는 JRE 1.4를 지원하지 않습니다. JDBC 드라이버를 사용하려면 JRE 1.4를 JRE 5.0 이상으로 업그레이드해야 합니다. 응용 프로그램이 JDK 5.0 이상과 호환되지 않아 다시 컴파일해야 하는 경우도 있습니다. 자세한 내용은 Sun Microsystems 웹 사이트의 설명서를 참조하십시오.


 

sqljdbc4.jar 클래스 라이브러리는 JDBC 4.0을 지원합니다. 이 라이브러리에는 sqljdbc.jar의 모든 기능과 함께 새로운 JDBC 4.0 메서드가 포함되어 있습니다.

sqljdbc4.jar 클래스 라이브러리에는 JRE(Java Runtime Environment) 버전 6.0 이상이 필요합니다. JRE 1.4 또는 5.0에서 sqljdbc4.jar을 사용하면 예외가 발생합니다.

ms378422.note(ko-kr,SQL.105).gif참고:
응용 프로그램을 JRE 6.0에서 실행해야 하는 경우에는 JDBC 4.0 기능을 사용하지 않더라도 sqljdbc4.jar을 사용하십시오.

 

[struts web.xml 참조하기]

 

ServletConfig config = this.getServlet();
String configStr = config.getInitParameter("config");  
System.out.println("configStr: " + configStr);


jar cvf ..\examples.war *

<Host appBase="D:\WebRoot\study" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">

 

[ 자동 리로드 ]

 

C:\tomcat-5.5.17\conf\Catalina\localhost\ROOT.xml

 

<Context path="" docBase="D:\WebRoot\study\ROOT" debug="0" reloadable="true" crossContext="true"/>

 

컨텍스트 이름별로 xml파일을 만든다.

 

[ 환경설정 ]

JAVA_HOME

CATALINA_HOME

CLASSPATH

import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;

 

public class CLASSNAME extends HttpServlet{

 

     public void init(ServletConfig config) throws ServletException {

          super.init(config);

     }

 

     public FUNCTION(){

          javax.servlet.ServletContext  servletContext  = getServletContext();

     }

}

 

ServletContext를 사용하기 위해선 init 메소드에서 super.init(config)를 해줘야한다.

(이유는 잘 모르겠다. 그에 답은 :http://okjsp.pe.kr/seq/40698)

 

ServletContext 객체를 얻을 수 있는 메서드는 HttpServlet 클래스의 getServletContext()이다.

(엄청 해깔린다. 이런식으로 ServletContext 의 servletContext 를 파라미터로 보내서 사용하면 좋을듯 싶다.

isELIgnored="false"         jstl 사용함

request.setCharacterEncoding("euc-kr");        한글 form 넘어온거

Properties 를 한번 사용할려고 여기저기, 자료를 찾을려고 기웃거려 봤는데..

워낙, 초보적인 내용이었는지.. 정리된것이 없더군요.


제가 가지고 있는 소스에 관련된 부분이 있어서.. 여기에 올립니다.

저초럼, 초보인 분에게 작은 도움이 될것 같아 올려봅니다.


......

간단히, 소스를 설명하자면..

PropertiesTest 실행할때

test.properties 라는 프로퍼티 파일을 가져오는데..

argument 가 있으면, test.properties 의 name 에 해당하는 value 를 불러오는거구요..

argument 가 없으면, test.properties 이의 프로퍼트에 value 을 변경시켜주는겁니다.~


test.properties 는 'PropertiesTest' class 가 있는 같은 디렉토리 위치에 있어야 겠지요.~


//===============================================================

//PropertiesTest.java
//===============================================================

import java.util.*;
import java.io.*;

class PropertiesTest {  

    public static void main(String[] args)  throws IOException   {
        Properties props = new Properties();
        if ( args.length == 0 )  {
            props.put("Name", "홍길동");
            props.put("Address", "Korea");
            props.store( new FileOutputStream("test.properties"), "My Comment");
        } else  {
            props.load( new FileInputStream("test.properties") );
        }

        System.out.println( "Name: " + props.getProperty("Name") );
        System.out.println( "Address: " + props.getProperty("Address") );
    }
}



//===============================================================

//test.properties

//===============================================================

#My Comment
Name=evergreen

Address=Korea

[Request  객체]

 

요청 피라미터 관련 메소드

 

String          getParameter(String name)                  피라미터의 값을 읽는다

String[]       getParameterValues(String name)        체크박스 같은 복수의 값을 배열로 읽는다

                  getRemoteAddr()                               아이피 얻기

                  request.setCharacterEncoding("euc-kr");          한글

 

 

HTTP 헤더 관련 메소드

 

String          getRemoteHost()                                클라이언드 이름 얻기

String          getRemoteAddr()                                클라이언트 IP주소 얻기

 

Date() -> String 타입

Date date1 = new Date();

String test = date1.toString();

 

 

날짜 변환 예제

<%@ page import = "java.text.DateFormat" %>
<%@ page import = "java.text.SimpleDateFormat" %>
<%@ page import = "java.util.Date" %>

 

Date date1 = new Date();
long time1 = date1.getTime();
long time2 = 1152393007234L;

 

// long 타입 시간을 문자열 날짜&시간으로 구하기

SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
String strDate = df.format(time1);

 

// 문자열로 구해진 날짜&시간 Date() 타입으로 변경하기
DateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date birthDay = sdFormat.parse(strDate);

 

int(long) -> String 변환

Date nowDate = new Date();
long test = nowDate.getTime();

String test1 = Long.toString(test);  // int 일경우 Integer.

 

String  -> long 변환

long tet = Long.parseLong(long 타입 값);

 

파일 이동

File fileMove1 = new File(request.getRealPath("/") + "board/pds/" + fileName);
  File fileMove2 = new File(request.getRealPath("/") + "board/pds/" + tab + "/" + fileName);

  fileMove1.renameTo(fileMove2);

 

[ 올림/반올림/자름 ]

Math.ceil(double) 무조껀 올림

Math.floor(double) 무조껀 자름

Math.round(double) 반 올림

100 : Continue
101 : Switching protocols
200 : OK, 에러없이 전송 성공
201 : Created, POST 명령 실행 및 성공
202 : Accepted, 서버가 클라이언트 명령을 받음
203 : Non-authoritative information, 서버가 클라이언트 요구 중 일부 만 전송
204 : No content, 클라언트 요구을 처리했으나 전송할 데이터가 없음
205 : Reset content
206 : Partial content
300 : Multiple choices, 최근에 옮겨진 데이터를 요청
301 : Moved permanently, 요구한 데이터를 변경된 임시 URL에서 찾았음
302 : Moved temporarily, 요구한 데이터가 변경된 URL에 있음을 명시
303 : See other, 요구한 데이터를 변경하지 않았기 때문에 문제가 있음
304 : Not modified
305 : Use proxy
400 : Bad request, 클라이언트의 잘못된 요청으로 처리할 수 없음
401 : Unauthorized, 클라이언트의 인증 실패
402 : Payment required, 예약됨
403 : Forbidden, 접근이 거부된 문서를 요청함
404 : Not found, 문서를 찾을 수 없음
405 : Method not allowed, 리소스를 허용안함
406 : Not acceptable, 허용할 수 없음
407 : Proxy authentication required, 프록시 인증 필요
408 : Request timeout, 요청시간이 지남
409 : Conflict
410 : Gone, 영구적으로 사용할 수 없음
411 : Length required
412 : Precondition failed, 전체조건 실패
413 : Request entity too large,
414 : Request-URI too long, URL이 너무 김
415 : Unsupported media type
500 : Internal server error, 내부서버 오류(잘못된 스크립트 실행시)
501 : Not implemented, 클라이언트에서 서버가 수행할 수 없는 행동을 요구함
502 : Bad gateway, 서버의 과부하 상태
503 : Service unavailable, 외부 서비스가 죽었거나 현재 멈춤 상태
504 : Gateway timeout
505 : HTTP version not supported

+ Recent posts