🍁주소록 구현
Ajax는 화면 깜박임 없이 데이터를 주고받기 때문에 눈에 보이는 페이지를 여러 장 만들지 않고 한 장으로 구현한다.
테이블 형태로 주소록 목록을 만들고, 입력하는 화면은 다른 페이지에 만들지 않고 해당 페이지의 팝업이나 아래에 폼으로 만든다.
Ajax를 사용하지 않는 페이지는 각 기능을 별도의 페이지로 만든다는 특징이 있다. 그래서 Ajax를 쓰지 않을 때에는 CRUD를 구현할 때 4개의 독립적인 페이지를 생성한다. 반면에 Ajax를 사용하면 모든 기능을 한 장으로 구현하기 때문에 페이지가 복잡해진다.
https://fonts.google.com/icons
https://docs.github.com/ko/copilot
jackson 라이브러리
Jackson을 검색하고 Jackson Databind를 클릭한다.
https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind/2.15.2
2.15.2 버전 jar 파일을 설치하여 lib 폴더에 복사한다.
이 라이브러리는 추후에 파싱할 때 사용한다.
🍂json simple 라이브러리
https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple/1.1.1
bundle을 클릭하여 다운로드한다.
json simple 라이브러리는 JSONObject라는 HashMap 성질의 클래스가 있다.
JSONObject
JSONObject obj1 = new JSONObject();
obj1.put("name", "Isaac");
obj1.put("age", "24");
//{"name":"Isaac","age":"24"}
System.out.println(obj1.toString());
JSONObject
JSONObject obj2 = new JSONObject();
obj2.put("name", "Sopia");
obj2.put("age", "25");
JSONArray arr = new JSONArray();
arr.add(obj1);
arr.add(obj2);
System.out.println(arr.toString());
객체를 조작해 배열을 덤프하여 출력할 수 있다.
완성 화면
초기화면
데이터 추가
데이터 수정
데이터 삭제
script.sql
- AjaxTest
--script.sql
select * from tblAddress;
drop TABLE tblAddress;
create TABLE tblAddress (
seq NUMBER primary key,
name VARCHAR2(30) not null,
age NUMBER not null,
gender CHAR(1) not null,
address VARCHAR2(300) not null,
regdate DATE default sysdate not null
);
create sequence seqAddress;
drop sequence seqAddress;
insert into tblAddress (seq, name, age, gender, address, regdate)
values (seqAddress.nextVal, 'Isaac', 24, 'm', '서울시 강남구 역삼동', default);
insert into tblAddress (seq, name, age, gender, address, regdate)
values (seqAddress.nextVal, 'Sopia', 25, 'f', '서울시 강남구 역삼동', default);
insert into tblAddress (seq, name, age, gender, address, regdate)
values (seqAddress.nextVal, 'Lee', 23, 'm', '서울시 강남구 역삼동', default);
insert into tblAddress (seq, name, age, gender, address, regdate)
values (seqAddress.nextVal, 'itsh', 27, 'm', '서울시 강남구 역삼동', default);
insert into tblAddress (seq, name, age, gender, address, regdate)
values (seqAddress.nextVal, 'itsha', 28, 'f', '서울시 강남구 역삼동', default);
select * from tblAddress order by seq;
commit;
rollback;
select seq, name, age, gender, address, to_char(regdate, 'yyyy-MM-dd') as regdate from tblAddress order by seq desc;
select * from tblAddress;
ex08.java
- AjaxTest > src/main/java > com.test.ajax.controller
package com.test.ajax.controller;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ex08.do")
public class Ex08 extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
RequestDispatcher dispatcher = req.getRequestDispatcher("/WEB-INF/views/ex08.jsp");
dispatcher.forward(req, resp);
}
}
ex08.jsp
- AjaxTest > src/main/webapp/WEB-INF/views
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>주소록</title>
<link rel="stylesheet" href="http://pinnpublic.dothome.co.kr/cdn/example-min.css">
<style>
#list th:nth-child(1) { width: 50px; }
#list th:nth-child(2) { width: 50px; }
#list th:nth-child(3) { width: 50px; }
#list th:nth-child(4) { width: 200px; }
#list th:nth-child(5) { width: 100px; }
#list th:nth-child(6) { width: 50px; }
#list td { text-align: center; }
#list td:nth-child(4) { text-align: Left; }
#add { display: none; }
#btnAdd { display: none; }
</style>
</head>
<body>
<h1>Address <small>ajax</small></h1>
<table id="list">
<thead>
<tr>
<th>이름</th>
<th>나이</th>
<th>성별</th>
<th>주소</th>
<th>날짜</th>
<th></th>
</tr>
</thead>
<tbody>
<!--
<tr>
<td>Isaac</td>
<td>24</td>
<td>남자</td>
<td>서울시 강남구 역삼동</td>
<td>2023-10-27</td>
<td>
<span class="material-symbols-outlined">edit</span>
<span class="material-symbols-outlined">delete</span>
</td>
</tr>
-->
</tbody>
</table>
<form id="addForm">
<div><button type="button" id="toggleAdd" class="out">펼치기</button></div>
<table id="add" class="vertical">
<tr>
<th>이름</th>
<td><input type="text" name="name" id="name" class="short"></td>
</tr>
<tr>
<th>나이</th>
<td><input type="number" name="age" id="age" min="1" max="100"></td>
</tr>
<tr>
<th>성별</th>
<td>
<select name="gender" id="gender">
<option value="m">남자</option>
<option value="f">여자</option>
</select>
</td>
</tr>
<tr>
<th>주소</th>
<td><input type="text" name="address" id="address" class="full"></td>
</tr>
</table>
<div id="btnAdd">
<button type="button" class="add">등록하기</button>
</div>
</form>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="http://pinnpublic.dothome.co.kr/cdn/example-min.js"></script>
<script>
function load() {
//기존 <tr> 삭제
$('#list tbody').html('');
$.ajax({
type: 'GET',
url: '/ajax/list.do', //list라는 servlet에게 주소록 전부를 달라고 요청
dataType: 'json',
success: function(result) {
//받아온 데이터를 가지고 화면에 보일 수 있도록 추가 작업
//alert(result.length);
$(result).each((index, item) => {
//console.log(item);
$('#list tbody').append(`
<tr>
<td>\${item.name}</td>
<td>\${item.age}</td>
<td>\${item.gender =='m' ? '남자' : '여자'}</td>
<td>\${item.address}</td>
<td>\${item.regdate}</td>
<td>
<span class="material-symbols-outlined" onclick="edit(\${item.seq});" style="cursor: pointer">edit</span>
<span class="material-symbols-outlined" onclick="del(\${item.seq});" style="cursor: pointer">delete</span>
</td>
</tr>
`);
});
},
error: function(a,b,c) {
console.log(a,b,c);
}
});
}
//페이지를 시작하자마자 load() 함수 호출
//Servlet에게 위임하지 않고 Ajax로 데이터를 가져오는 작업
load();
$('#toggleAdd').click(function() {
if ($('#add').css('display') == 'none') {
$('#add').css('display', 'table');
$(this).removeClass('out');
$(this).addClass('in');
$(this).text('접기');
$('#btnAdd').css('display', 'block');
$('#name').focus();
} else {
$('#add').css('display', 'none');
$(this).removeClass('in');
$(this).addClass('out');
$(this).text('펼치기');
$('#btnAdd').css('display', 'none');
}
//$('#add', '#btnAdd').toggle();
//$(this).toggleClass('out');
//$(this).toggleClass('in');
//toggle로 위 코드와 기능은 동일하다.
});
//추가
$('#btnAdd > button').click(function() {
//alert($('#addForm').serialize()); //직렬화
let serializedData = $('#addForm').serialize();
//ajax > 입력 데이터 전송 > insert
$.ajax({
type: 'POST',
url: '/ajax/add.do',
data: serializedData,
dataType: 'json',
success: function(result) {
//alert(result.result);
if(result.result == 1) {
//목록 새로 고침
load();
//입력 폼 초기화
$("#name").val('');
$("#age").val('');
$("#gender").val('m');
$("#address").val('');
$("#name").focus();
} else {
alert('failed');
}
},
error: function(a,b,c) {
console.log(a,b,c);
}
})
});
//수정
function edit(seq) {
//클릭 > 수정 버튼(<span>)
//$(this).parent().parent()
let name = $(event.target).parents('tr').children().eq(0).text();
let age = $(event.target).parents('tr').children().eq(1).text();
let gender = $(event.target).parents('tr').children().eq(2).text();
let address = $(event.target).parents('tr').children().eq(3).text();
//부모들 중에 처음 만나는 tr을 parents에서 찾음
$(event.target).parents('tr').children().eq(0).html(`<input type="text" class="short" style="width:50px; text-align:center;" value="\${name}" onblur="editName(\${seq});">`);
$(event.target).parents('tr').children().eq(1).html(`<input type="number" class="short" style="width:50px; text-align:center;" value="\${age}" min="1" max="100" onblur="editAge(\${seq});">`);
$(event.target).parents('tr').children().eq(2).html(`
<select onblur="editGender(\${seq});">
<option value="m" \${gender == '남자' ? 'selected' : ''}>남자</option>
<option value="f" \${gender == '여자' ? 'selected' : ''}>여자</option>
</select>
`);
$(event.target).parents('tr').children().eq(3).html(`<input type="text" class="short" style="width:200px; text-align:left;" value="\${address}" onblur="editAddress(\${seq});">`);
}
function editName(seq) {
//alert(seq);
//alert($(event.target).val());
const temp = $(event.target); //수정을 위한 텍스트 박스
//값이 수정 > onchange 발생 > ajax > 서버 전송 > update
$.ajax({
type: 'POST',
url: '/ajax/edit.do',
data: {
column: 'name', //고정값
value: $(event.target).val(),
seq: seq
},
dataType: 'json',
success: function(result) {
if (result.result == 1) {
//수정 완료 > td의 상태를 원래대로 되돌리기 (편집 전 상태)
//<input type="text" class="short" style="width:50px; text-align:center;" value="\${name}" onchange="editName(\${seq});">
temp.parent().text(temp.val()); //수정을 위한 텍스트 상자를 텍스트 상자의 값으로 변환
} else {
alert('failed');
}
},
error: function(a,b,c) {
console.log(a,b,c);
}
});
}
function editAge(seq) {
const temp = $(event.target);
$.ajax({
type: 'POST',
url: '/ajax/edit.do',
data: {
column: 'age',
value: $(event.target).val(),
seq: seq
},
dataType: 'json',
success: function(result) {
if (result.result == 1) {
temp.parent().text(temp.val());
} else {
alert('failed');
}
},
error: function(a,b,c) {
console.log(a,b,c);
}
});
}
function editGender(seq) {
const temp = $(event.target);
$.ajax({
type: 'POST',
url: '/ajax/edit.do',
data: {
column: 'gender',
value: $(event.target).val(),
seq: seq
},
dataType: 'json',
success: function(result) {
if (result.result == 1) {
temp.parent().text(temp.val() == 'm' ? '남자' : '여자');
} else {
alert('failed');
}
},
error: function(a,b,c) {
console.log(a,b,c);
}
});
}
function editAddress(seq) {
const temp = $(event.target);
$.ajax({
type: 'POST',
url: '/ajax/edit.do',
data: {
column: 'address',
value: $(event.target).val(),
seq: seq
},
dataType: 'json',
success: function(result) {
if (result.result == 1) {
temp.parent().text(temp.val());
} else {
alert('failed');
}
},
error: function(a,b,c) {
console.log(a,b,c);
}
});
}
//삭제
function del(seq) {
if (confirm('delete?')) {
$.ajax({
type: 'POST',
url: '/ajax/del.do',
data: 'seq=' + seq,
dataTyle: 'json',
success: function(result) {
if (result.result) {
load();
} else {
alert('failed');
}
},
error: function(a,b,c) {
console.log(a,b,c);
}
})
}
}
</script>
</body>
</html>
List.java
- AjaxTest > src/main/java > com.test.ajax.service
package com.test.ajax.service;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import com.test.ajax.model.AddressDTO;
import com.test.ajax.repository.AjaxDAO;
@WebServlet("/list.do")
public class List extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1. DB 작업 > select
//2. 반환 > json 변환 > ajax에게 반환
//1.
AjaxDAO dao = new AjaxDAO();
ArrayList<AddressDTO> list = dao.listAddress();
//2.
//list > json 변환
/*
[
{
"seq": "1",
"name": "Isaac",
"age": "24"
},
{
"seq": "2",
"name": "Sopia",
"age": "25"
},
]
*/
//위의 json 변환 작업을 편하게 하는 jackson 라이브러리를 사용한다.
//HashMap 성질
/*
JSONObject obj1 = new JSONObject();
obj1.put("name", "Isaac");
obj1.put("age", "24");
//{"name":"Isaac","age":"24"}
System.out.println(obj1.toString());
JSONObject obj2 = new JSONObject();
obj2.put("name", "Sopia");
obj2.put("age", "25");
JSONArray arr = new JSONArray();
arr.add(obj1);
arr.add(obj2);
System.out.println(arr.toString());
*/
//ArrayList<AddressDTO> list -> JSONArray
//AddressDTO -> JSONObject
JSONArray arr = new JSONArray();
for (AddressDTO dto : list) {
//AddressDTO 1개 > JSONObject 1개
JSONObject item = new JSONObject();
item.put("seq", dto.getSeq());
item.put("name", dto.getName());
item.put("age", dto.getAge());
item.put("gender", dto.getGender());
item.put("address", dto.getAddress());
item.put("regdate", dto.getRegdate());
arr.add(item);
}
//System.out.println(arr.toString());
resp.setContentType("application/json");
resp.setCharacterEncoding("UTF-8");
PrintWriter writer = resp.getWriter();
writer.print(arr.toString());
writer.close();
//현재는 필요하지 않은 코드
//RequestDispatcher dispatcher = req.getRequestDispatcher("/WEB-INF/views/list.jsp");
//dispatcher.forward(req, resp);
}
}
요청을 받으면 업무를 보는 이러한 작업(List, Add 등)은 service 패키지에 많이 작성하는 편이다.
Add.java
- AjaxTest > src/main/java > com.test.ajax.service
package com.test.ajax.service;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
import com.test.ajax.model.AddressDTO;
import com.test.ajax.repository.AjaxDAO;
@WebServlet("/add.do")
public class Add extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1. 데이터 가져오기
//2. DB작업 > insert
//3. 피드백 반환
//1.
String name = req.getParameter("name");
String age = req.getParameter("age");
String gender = req.getParameter("gender");
String address = req.getParameter("address");
//2.
AjaxDAO dao = new AjaxDAO();
AddressDTO dto = new AddressDTO();
dto.setName(name);
dto.setAge(age);
dto.setGender(gender);
dto.setAddress(address);
int result = dao.addAddress(dto);
//3.
JSONObject obj = new JSONObject();
obj.put("result", result);
resp.setContentType("application/json");
resp.setCharacterEncoding("UTF-8");
PrintWriter writer = resp.getWriter();
writer.print(obj.toString());
writer.close();
//RequestDispatcher dispatcher = req.getRequestDispatcher("/WEB-INF/views/add.jsp");
//dispatcher.forward(req, resp);
}
}
Edit.java
- AjaxTest > src/main/java > com.test.ajax.service
package com.test.ajax.service;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
import com.test.ajax.repository.AjaxDAO;
@WebServlet("/edit.do")
public class Edit extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1. 데이터 가져오기(seq, column, value)
//2. DB 작업 > update
//3. 피드백 > JSON
//1.
String seq = req.getParameter("seq");
String column = req.getParameter("column");
String value = req.getParameter("value");
//2.
AjaxDAO dao = new AjaxDAO();
//지금 있는 dto 구조로 넘기기 번거로우므로 이번에는 HashMap으로 넘기도록 한다.
//AddressDTO dto = new AddressDTO();
//dto.setSeq(seq);
HashMap<String,String> map = new HashMap<String,String>();
map.put("seq", seq);
map.put("column", column);
map.put("value", value);
int result = dao.editAddress(map);
//3.
//Add.java의 피드백 3번과 코드가 동일하다.
JSONObject obj = new JSONObject();
obj.put("result", result);
resp.setContentType("application/json");
resp.setCharacterEncoding("UTF-8");
PrintWriter writer = resp.getWriter();
writer.print(obj.toString());
writer.close();
//RequestDispatcher dispatcher = req.getRequestDispatcher("/WEB-INF/views/edit.jsp");
//dispatcher.forward(req, resp);
}
}
Del.java
- AjaxTest > src/main/java > com.test.ajax.service
package com.test.ajax.service;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject;
import com.test.ajax.repository.AjaxDAO;
@WebServlet("/del.do")
public class Del extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//1. 데이터 가져오기 (seq)
//2. 데이터 처리하기 (deleter)
//3. 피드백 (JSON)
//1.
String seq = req.getParameter("seq");
//2.
AjaxDAO dao = new AjaxDAO();
int result = dao.delAddress(seq);
//3.
JSONObject obj = new JSONObject();
obj.put("result", result);
resp.setContentType("application/json");
resp.setCharacterEncoding("UTF-8");
PrintWriter writer = resp.getWriter();
writer.print(obj.toString());
writer.close();
//RequestDispatcher dispatcher = req.getRequestDispatcher("/WEB-INF/views/del.jsp");
//dispatcher.forward(req, resp);
}
}
AddressDTO.java
- AjaxTest > src/main/java > com.test.ajax.model
package com.test.ajax.model;
public class AddressDTO {
private String seq;
private String name;
private String age;
private String gender;
private String address;
private String regdate;
public String getSeq() {
return seq;
}
public void setSeq(String seq) {
this.seq = seq;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getRegdate() {
return regdate;
}
public void setRegdate(String regdate) {
this.regdate = regdate;
}
}
DB의 테이블 1개당 DTO를 1개 만드는 게 일반적이다.
즉, 테이블에 대응해서 DTO를 만든다.
컬럼 이름을 멤버 변수로 사용하는 게 가독성이 높기 때문이다.
AjaxDAO.java
- AjaxTest > src/main/java > com.test.ajax.repository
package com.test.ajax.repository;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import com.test.ajax.controller.DBUtil;
import com.test.ajax.model.AddressDTO;
import com.test.ajax.model.ChromiDTO;
import com.test.ajax.model.MemoDTO;
public class AjaxDAO {
private Connection conn;
private Statement stat;
private PreparedStatement pstat;
private ResultSet rs;
public AjaxDAO() {
this.conn = DBUtil.open();
}
public ArrayList<AddressDTO> listAddress() {
try {
String sql = "select seq, name, age, gender, address, to_char(regdate, 'yyyy-MM-dd') as regdate from tblAddress order by seq desc";
//최신순 정렬 및 날짜를 년월일만 출력하므로 DB에서도 년월일만 가져옴
stat = conn.createStatement();
rs = stat.executeQuery(sql);
ArrayList<AddressDTO> list = new ArrayList<AddressDTO>();
while (rs.next()) {
//레코드 1줄 == AddressDTO 1개
AddressDTO dto = new AddressDTO();
dto.setSeq(rs.getString("seq"));
dto.setName(rs.getString("name"));
dto.setAge(rs.getString("age"));
dto.setGender(rs.getString("gender"));
dto.setAddress(rs.getString("address"));
dto.setRegdate(rs.getString("regdate"));
list.add(dto);
}
return list;
} catch (Exception e) {
System.out.println("AjaxDAO.listAddress()");
e.printStackTrace();
}
return null;
}
public int addAddress(AddressDTO dto) {
try {
String sql = "insert into tblAddress (seq, name, age, gender, address, regdate) values (seqAddress.nextVal, ?, ?, ?, ?, default)";
pstat = conn.prepareStatement(sql);
pstat.setString(1, dto.getName());
pstat.setString(2, dto.getAge());
pstat.setString(3, dto.getGender());
pstat.setString(4, dto.getAddress());
return pstat.executeUpdate();
} catch (Exception e) {
System.out.println("AjaxDAO.addAddress()");
e.printStackTrace();
}
return 0;
}
public int editAddress(HashMap<String,String> map) {
try {
//이름, 나이, 성별, 주소 모두 각자의 컬럼명으로 수정하므로 호환이 된다.
String sql = String.format("update tblAddress set %s = ? where seq = ?", map.get("column"));
pstat = conn.prepareStatement(sql);
pstat.setString(1, map.get("value"));
pstat.setString(2, map.get("seq"));
return pstat.executeUpdate();
} catch (Exception e) {
System.out.println("AjaxDAO.editAddress()");
e.printStackTrace();
}
return 0;
}
public int delAddress(String seq) {
try {
String sql = "delete from tblAddress where seq = ?";
pstat = conn.prepareStatement(sql);
pstat.setString(1, seq);
return pstat.executeUpdate();
} catch (Exception e) {
System.out.println("AjaxDAO.delAddress()");
e.printStackTrace();
}
return 0;
}
}
DBUtil
- AjaxTest > src/main/java > com.test.ajax.repository
package com.test.ajax.respository;
import java.sql.Connection;
import java.sql.DriverManager;
public class DBUtil {
private static Connection conn;
public static Connection open() {
//연결 문자열, Connection String
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String id = "hr";
String pw = "java1234";
try {
//외부 입출력 작업 시 예외 처리 필수
//JDBC 드라이버 로딩(관련 클래스 정보)
Class.forName("oracle.jdbc.driver.OracleDriver");
//Connection 객체 생성 + 오라클 접속 완료
conn = DriverManager.getConnection(url, id, pw);
return conn;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Connection open(String server, String id, String pw) {
//프로젝트 시 사용
String url = "jdbc:oracle:thin:@" + server + ":1521:xe";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, id, pw);
return conn;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}