VIEWDB3_TEST.jsp 1.97 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.sql.*,com.csc.library.database.ConnectDB,com.csc.library.utilities.UProfile"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<% 
	 UProfile up=(UProfile)session.getAttribute("userprofile");
	if(up!=null){
%>
	<form name="cscform" method="post">
	


<p align="center"><strong>Update Data</strong></p> 
		<table align="center">
			<tr>
				<td width="104">DataBase :</td>
				<td width="317"><input type="text" size="15" name="db" value='<%=request.getParameter("db")%>'></td>
			</tr>
			<tr>
				<td height="130">SQL Command :</td>
				<td><textarea rows="8" cols="50" name="cmd" ></textarea></td>
			</tr>
			<tr>
				<td  align="center" colspan="2"><input type="submit" name="submit">&nbsp;&nbsp;<input type="reset" name="reset"></td>
			</tr>
			<%
				if(request.getParameter("submit") !=null) {
					String db = request.getParameter("db");
					String sql = request.getParameter("cmd");
					ConnectDB  cdb =null;
					Connection conn = null;
					Statement  st =null;
					out.println(" Old SQL Command :: "+request.getParameter("cmd")+"<BR><BR>");
					try{
						cdb = new ConnectDB();
						conn = cdb.getConnection(db);
						st = conn.createStatement();
						if(sql.indexOf(";")>-1){
							String[] sql2 = sql.split(";");
							for(int c=0;c<sql2.length;c++){
								sql = sql2[c];
								st.executeUpdate(sql);
								conn.commit();
							}
						}else{
							st.executeUpdate(sql);
							conn.commit();
						}
					}catch(Exception e){
						out.println(" Error ::  "+e);
					}finally{
						if(st!=null){
							st.close();
						}
						if(conn != null){
							conn.commit();
							conn.close();
						}					
					}
				}
			%>

		</table>
	
</form>
<%}%>		
</body>
</html>