µÇµ¹¾Æ°¡±â
<%@ page contentType="text/xml; charset=EUC-KR" %>
<%@ page import="java.sql.*,kr.co.comsquare.rwXmlLib.*,java.util.*,kr.co.comsquare.db.*,kr.co.comsquare.util.Tokenizer" %>
<%
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
RwXml rx = new RwXml();
int rootNodeID = rx.rootNodeID;
int cur_depth=0;
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@203.109.25.69:1521:COMSDB";
String id = "scott";
String pw = "tiger";
try
{
// ¸Å¿ì Áß¿ä!
/////////////////////
request.setCharacterEncoding("EUC-KR");
////////////////////
con = DriverManager.getConnection(url, id, pw);
if(con == null) throw new SQLException("Connection Error");
// 1. request
// ¿¹) http://edu.comsquare.co.kr:7001/MyTest/multi_update_huge.jsp?code=s&condition=
//...........................................................................................................
String data = request.getParameter( "data" );
// data = new String(data.getBytes("8859_1"),"KSC5601");
/*
if ( res_code == null )
{
throw new SQLException("res_code = null");
}
*/
int result = 0;
// con.setAutoCommit(false);
SaveResultSet totalRs = new SaveResultSet();
//////////////////////
//±¸ºÐÀÚ°¡ ±âº»ÀûÀ¸·Î ¼ÂÆÃµÊ (°¡·Î±¸ºÐ : ¢Ë, ¼¼·Î±¸ºÐ : ¢Ì)
Tokenizer.getSaveResultSet(data,"smode", totalRs);
//±¸ºÐÀÚ ÁöÁ¤
//http://localhost:8080/test/dbupdate.jsp?data=m^test1^test2|i^tttt10^1111|i^tttt18^22222|i^tttt71^3333|i^tttt16^4444|
// Tokenizer.getSaveResultSet(data,"smode", totalRs, "^", "|");
//////////////////////
StringBuffer query = new StringBuffer();
// INSERT
while (totalRs.next()) {
if( (totalRs.get("smode")).equals("i") ){
query.append("INSERT INTO test ( test1, test2) ");
query.append("VALUES ( ?, ?)");
pstmt = con.prepareStatement(query.toString());
if (pstmt == null) throw new SQLException("Statement Error");
pstmt.setString(1, totalRs.get("test1"));
pstmt.setString(2, totalRs.get("test2"));
result += pstmt.executeUpdate();
}else if( (totalRs.get("smode")).equals("u") ){
query.append("UPDATE test SET test1 = ?, test2 = ? ");
query.append("WHERE test1 = ? ");
pstmt = con.prepareStatement(query.toString());
if (pstmt == null) throw new SQLException("Statement Error");
pstmt.setString(1, totalRs.get("test1"));
pstmt.setString(2, totalRs.get("test2"));
pstmt.setString(3, totalRs.get("test1"));
result += pstmt.executeUpdate();
}else if( (totalRs.get("smode")).equals("d") ){
query.append("DELETE FROM test ");
query.append("WHERE test1 = ? ");
pstmt = con.prepareStatement(query.toString());
if (pstmt == null) throw new SQLException("Statement Error");
pstmt.setString(1, totalRs.get("test1"));
result += pstmt.executeUpdate();
}
query.setLength(0);
}
con.commit();
rx.setEncoding( "UTF-8" );
//³ëµå »ý¼º ½ÃÀÛ ¹ÝȯÇü int ÇöÀç depth ¹Ýȯ
cur_depth = rx.add(rootNodeID, "iud_result", String.valueOf(result));
//ȸé Ç¥½Ã
out.println(rx.xmlFlush());
//</root>ÅÂ±× ´ÝÀ½
out.println(rx.xmlEndFlush());
}
catch(Exception e)
{
getServletContext().log( "Comsquare_error => jsp File : dbupdate_toralrs.jsp", e);
rx.setErrorMsg("resultKM", e.getMessage());
out.println(rx.xmlFlush());
out.println(rx.xmlEndFlush());
}
finally
{
if(rs != null) try { rs.close(); } catch(Exception e1) {}
if(pstmt != null) try { pstmt.close(); } catch(Exception e1) {}
if(con != null) try { con.close(); con = null; } catch(Exception e1) {}
// try { ctx.close();} catch (Exception e){}
}
%>
µÇµ¹¾Æ°¡±â