在jsp中向oracle插入一行数据
<%@page contentType="text/html;charset=gbk"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*,java.io.*,java.text.*"%>
<%!
public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:sales";
public static final String DBUSER = "scott";
public static final String DBPASS = "tiger";
%>
<%
Connection conn = null;//数据库连接
PreparedStatement pstmt = null;//数据库操作
ResultSet rs = null;//查询结果集
%>
<%
Class.forName(DBDRIVER);//加载数据库
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
String empno = request.getParameter("empno");
String ename = request.getParameter("ename");
String mgr = request.getParameter("mgr");
String job = request.getParameter("job");
String hiredate = request.getParameter("hiredate");
String sal = request.getParameter("sal");
String comm = request.getParameter("comm");
String deptno = request.getParameter("deptno");
String sql = "insert into emp values("+ Integer.parseInt(empno)+",'"+ename+"',"+Integer.parseInt(mgr)+",'"+job+"',"+to_date(hiredate,'yyyy-mm-dd')+","+Float.parseFloat(sal) +","+Float.parseFloat(comm)+","+Integer.parseInt(deptno) +")";
pstmt = conn.prepareStatement(sql);//将预编译的sql语句存储在pstmt对象中
int i= pstmt.executeUpdate();
sql = "select * from emp";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
%>
<center>
<h1>添加后后的雇员表</h1>
<table border="1" width="80%">
<tr>
<td>雇员编号</td>
<td>雇员姓名</td>
<td>上级编号</td>
<td>工作</td>
<td>雇用日期</td>
<td>工资</td>
<td>奖金</td>
<td>部门号</td>
</tr>
<%
while(rs.next()) {
int empno1 = rs.getInt(1);
String ename1 = rs.getString(2);
String job1 = rs.getString(3);