jquery : <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
JSTL : <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Chart.js : <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
Bootstrap:
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"> // 아이콘 등
spring release url) https://github.com/spring-projects/spring-framework/releases?after=v4.3.0.RC1
oracleDB 계정생성:
create user aaaa
identified by aaaa
default tablespace users
temporary tablespace temp
quota unlimited on users;
grant create session, create table
to aaaa;
jquery.zip
JSTL.zip
ojdbc6.jar
jsonlib.zip
Chart.js-master.zip
Chart.min.js
json 변환 코드 (jsonlib 내부 파일 모두 필요)
<%@page import="net.sf.json.JSONArray"%>
<%@page import="kr.or.kosta.Emp"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%
Class.forName("oracle.jdbc.OracleDriver");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
conn = DriverManager.getConnection("jdbc:oracle:thin:
@localhost:1521:XE","bituser","1004");
stmt = conn.createStatement();
String sql= "select empno ,ename , sal , job from emp";
rs = stmt.executeQuery(sql);
List<Emp> list = new ArrayList<>();
while(rs.next()){
Emp emp = new Emp();
emp.setEmpno(rs.getInt(1));
emp.setEname(rs.getString(2));
emp.setSal(rs.getInt(3));
emp.setJob(rs.getString(4));
list.add(emp);
}
//변환 작업(JSON 객체)
JSONArray jsonlist = JSONArray.fromObject(list);
%>
<%=jsonlist%>
<%
Member member = new Member();
// String json = "{" + "username:" + member.getName()+ ", userpwd:" + .....
// 위와 같은 번거로움을 없애주는 단 한줄의 코드가 바로 아래 코드
JSONObject obj = JSONObject.fromObject(member);
%>
<%= obj %>
JDBC 싱글톤
package kr.or.kosta.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.PreparedStatement;
public class Singleton_Helper {
private static Connection conn = null; //public > private
private Singleton_Helper() {}
public static Connection getConnection(String dsn) {
if(conn != null) {
//System.out.println("conn is not null");
return conn;
}
try {
if(dsn.equals("oracle")) {
Class.forName("oracle.jdbc.OracleDriver");
conn = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:XE","bituser","1004");
}else if(dsn.equals("mysql")) {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection
("jdbc:mysql://localhost:3306/superdb","superman","1004");
}
}catch(Exception e) {
System.out.println(e.getMessage());
}
System.out.println("conn return");
return conn;
}
public static void DBClose() {
if(conn != null) {
try {
conn.close();
conn = null;
}catch(Exception e) {
}
}
}
public static void close(Connection conn) {
if(conn != null) {
try {
conn.close();
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
public static void close(Statement stmt) {
if(stmt != null) {
try {
stmt.close();
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
public static void close(ResultSet rs) {
if(rs != null) {
try {
rs.close();
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
public static void close(PreparedStatement pstmt) {
if(pstmt != null) {
try {
pstmt.close();
}catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
}
DBCP
context.xml
<Resource maxWait="-1"
maxIdle="20"
maxActive="50"
password="1004"
username="bituser"
url="jdbc:oracle:thin:@localhost:1521:XE"
driverClassName="oracle.jdbc.OracleDriver"
type="javax.sql.DataSource"
auth="Container"
name="jdbc/oracle"
/>
src( ~.java)
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
//이름 기반으로 (WAS 안에서)
Context context = new InitialContext();
//ClassforName.() 처럼 '이름'으로 object retrieve 해주는 함수 lookup()
DataSource dbcp = (DataSource)context.lookup("java:comp/env/jdbc/oracle");
//POOL 안에서 연결 객체를 하나 얻어내는 코드
conn = dbcp.getConnection();
커넥션풀
탐켓에 컨텍스트엑스엠엘 가서 커넥션풀 코드 가져오고 dao단 코드도 가져와서 블로그에 두 개 올리기
Action.java, ActionForward.java
public interface Action {
public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Exception;
}
public class ActionForward {
private boolean isRedirect =false;
private String path = null;
public boolean isRedirect() {
return isRedirect;
}
public void setRedirect(boolean isRedirect) {
this.isRedirect = isRedirect;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}