<%@ page language="Java" import="java.sql.*" %> Insert DEPT

Insert DEPT

<% try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@marge:1521:W2K1", "SCOTT", "TIGER"); // Do the insert. try { PreparedStatement pstmt = conn.prepareStatement("INSERT INTO dept (deptno, dname, loc) VALUES (?,?,?)"); pstmt.setObject(1, request.getParameter("p_deptno")); pstmt.setObject(2, request.getParameter("p_dname")); pstmt.setObject(3, request.getParameter("p_loc")); int res = pstmt.executeUpdate(); out.println(" Insert DEPT Completed Successfully!

"); } catch (Exception ex) { out.println(" Error: " + ex.getLocalizedMessage() + "

"); } // Print out the contents of the table. Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM dept"); out.println(""); ResultSetMetaData rsmd = rs.getMetaData(); for (int i=1; i <= rsmd.getColumnCount(); i++) { out.println(""); } out.println(""); while (rs.next()) { out.println(""); for (int i=1; i <= rsmd.getColumnCount(); i++) { out.println(""); } out.println(""); } out.println("
 " + rsmd.getColumnName(i) + " 
 " + rs.getString(i) + " 
"); rs.close(); conn.close(); } catch (Exception ex) { out.println(" Error: " + ex.getLocalizedMessage() + "

"); } %>