package conn;
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConn {
private static DBConn db = new DBConn(); //객체생성
private DBConn() {} //생성자
public static DBConn getInstance() { // 메서드
return db;
}
public Connection getConnect(){
Connection con=null;
try {
Class.forName ("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection ("jdbc:oracle:thin:@//localhost:1521/xe","system","1234");
} catch (Exception e) {
e.printStackTrace();
}
return con;
}
}
action="/MVC2/FormController"
//결과 : http://localhost:8081/MVC2/FormController?custno=111111&custname=222&phone=333&address=444&joindate=&grade=&city=
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
String custno = request.getParameter("custno");
String custname = request.getParameter("custname");
String phone = request.getParameter("phone");
String address = request.getParameter("address");
String joindate = request.getParameter("joindate");
String grade = request.getParameter("grade");
String city = request.getParameter("city");
}
MemberVo m = new MemberVo();
m.setCustno(custno);
m.setCustname(custname);
m.setPhone(phone);
m.setAddress(address);
m.setJoindate(joindate);
m.setGrade(grade);
m.setCity(city);
int custno = Integer.parseInt(request.getParameter("custno"));
//String형인 값을 integer형으로 변경해줬다.
FormService serv = new FormServiceImpli();
// Service객체를 생성한다.
serv.insert(m);
//객체의 메서드인 insert를 호출한다.
try{
sql = " insert into member_tbl_02 ";
sql = sql + " (custno, custname, phone, address, joindate, grade, city ) " ;
sql = sql + " values(?,?,?,?,?,?,?) ";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, m.getCustno());
pstmt.setString(2,m.getCustname());
pstmt.setString(3,m.getPhone());
pstmt.setString(4,m.getAddress());
pstmt.setString(5, m.getJoindateS());
pstmt.setString(6, m.getGrade());
pstmt.setString(7, m.getCity());
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} finally{
if (pstmt != null){
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (con != null){
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}