listperson.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<jsp:directive.page import="java.sql.Date" />
<jsp:directive.page import="java.sql.Timestamp" />
<jsp:directive.page import="java.sql.SQLException"/><style type="text/css">body, td, th, input {font-size:12px; text-align:center; }</style>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott",
"Admin168");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from person");
%><form action="operateperson.jsp" method="get"> <table align=right>
<tr>
<td><a href="addperson.jsp">新建人员资料</a></td>
</tr>
</table>
<br> <br> <table bgcolor="#cccccc" cellpadding="1" cellspacing="1" width="80%"
align="center">
<tr bgcolor="#dddddd">
<th></th>
<th>ID</th>
<th>姓名</th>
<th>英文名</th>
<th>性别</th>
<th>年龄</th>
<th>生日</th>
<th>备注</th>
<th>记录创建时间</th>
<th>操作</th>
</tr>
<%
//遍历结果集,rs.next()返回结果集中是否还有下一条记录,如果有,自动滚动到下一条记录并返回true
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
String englishname = rs.getString("english_name");
String sex = rs.getString("sex");
int age = rs.getInt("age");
Date birthday = rs.getDate("birthday");
String description = rs.getString("description");
Timestamp createtime = rs.getTimestamp("create_time"); out.println("<tr bgcolor='#ffffff'>");
out.println(" <td><input type='checkbox' name='id' value='"
+ id + "'></td>");
out.println(" <td align='center'>" + id + "</td>");
out.println(" <td align='center'>" + name + "</td>");
out.println(" <td align='center'>" + englishname + "</td>");
out.println(" <td align='center'>" + sex + "</td>");
out.println(" <td align='center'>" + age + "</td>");
out.println(" <td align='center'>" + birthday + "</td>");
out.println(" <td align='center'>" + description + "</td>");
out.println(" <td align='center'>" + createtime + "</td>");
out.println(" <td align='center'>");
out.println(" <a href='operateperson.jsp?action=del&id="
+ id
+ "' onclick='return confirm(\"确定删除记录吗?\")'>删除</a>");
out.println(" <a href='operateperson.jsp?action=edit&id="
+ id + "'>修改</a>");
out.println(" </td>");
out.println("</tr>");
}
%> </table>
<table align="left">
<tr>
<td>
<input type='hidden' value='del' name='action'>
<a href='#'
onclick="var array=document.getElementsByName('id');
for(var i=0; i<array.length; i++){array[i].checked=true;}">全选</a>
<a href='#'
onclick="var array=document.getElementsByName('id');
for(var i=0; i<array.length; i++){array[i].checked=false;}">取消全选</a>
<input type='submit'
onclick="return confirm('即将删除所选择的记录。是否删除?');" value='删除'>
</td>
</tr>
</table>
</form>
<%
} catch (Exception e) {
e.printStackTrace();
} finally {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
}
%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"><title>My JSP 'listperson.jsp' starting page</title><meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--></head><body></body>
</html>
addperson.jsp<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String action = (String) request.getAttribute("action");
String id = (String) request.getAttribute("id");
String name = (String) request.getAttribute("name");
String englishname = (String) request.getAttribute("englishname");
String age = (String) request.getAttribute("age");
String sex = (String) request.getAttribute("sex");
String birthday = (String) request.getAttribute("birthday");
String description = (String) request.getAttribute("description");
String createtime = (String) request.getAttribute("create_time"); boolean isEdit = "edit".equals(action);
%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<style type="text/css">
body,td {
font-size: 12px;
}
</style>
<title><%=isEdit ? "修改人员资料" : "新建人员资料"%></title><meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--></head>
<body>
<form action="operateperson.jsp" method="post">
<script type="text/javascript" src="js/calendar.js"></script>
<input type="hidden" name="action" value="<%=isEdit ? "save" : "add"%>">
<fieldset>
<legend><%=isEdit ? "修改人员资料" : "新建人员资料"%></legend>
<table align="center">
<tr>
<td>ID:</td>
<td><input type="text" name="id" value="<%=isEdit ? id : ""%>" />
</td>
</tr>
<tr>
<td>姓名:</td>
<td><input type="text" name="name"
value="<%=isEdit ? name : ""%>" />
</td>
</tr>
<tr>
<td>英文名:</td>
<td><input type="text" name="englishname"
value="<%=isEdit ? englishname : ""%>" />
</td>
</tr>
<tr>
<td>性别:</td>
<td><input type="radio" name="sex" value="男" id="sex_male"
<%=isEdit && "男".equals(sex) ? "checked" : ""%> /><label
for="sex_male">男</label> <input type="radio" name="sex" value="女"
id="sex_female" <%=isEdit && "女".equals(sex) ? "checked" : ""%> /><label
for="sex_female">女</label></td>
</tr>
<tr>
<td>年龄:</td>
<td><input type="text" name="age"
value="<%=isEdit ? age : ""%>" />
</td>
</tr>
<tr>
<td>出生日期:</td>
<td><input type="text" name="birthday"
onfocus="setday(birthday)" value="<%=isEdit ? birthday : ""%>" />
<img alt="" src="images/calendar.gif" onclick="setday(birthday)">
</td>
</tr>
<tr>
<td>描述:</td>
<td><textarea rows="10" cols="30" name="description"><%=isEdit ? description : ""%></textarea>
</td>
</tr>
<tr>
<td>创建时间:</td>
<td><input type="text" name="createtime"
onfocus="setday(createtime)"
value="<%=isEdit ? createtime : ""%>" /> <img alt=""
src="images/calendar.gif" onclick="setday(createtime)"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="<%=isEdit ? "保存" : "添加人员信息"%>">
<input type="button" value="返回" onclick="history.go(-1); " /></td>
</tr>
</table>
</fieldset>
</form>
</body>
</html>

解决方案 »

  1.   

    operatepersson.jsp
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*"%>
    <jsp:directive.page import="java.sql.ResultSet" />
    <jsp:directive.page import="java.sql.SQLException" />
    <jsp:directive.page import="java.sql.PreparedStatement" />
    <jsp:directive.page import="java.text.SimpleDateFormat" />
    <jsp:directive.page import="java.sql.Timestamp" />
    <jsp:directive.page import="java.sql.Date" />
    <%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8"); String id = request.getParameter("id");
    String name = request.getParameter("name");
    String englishname = request.getParameter("englishname");
    String sex = request.getParameter("sex");
    String age = request.getParameter("age");
    String birthday = request.getParameter("birthday");
    String description = request.getParameter("description");
    String createtime = request.getParameter("createtime"); String action = request.getParameter("action"); if ("add".equals(action)) {
    String sql = "INSERT INTO PERSON "
    + "(ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES "
    + "('" + id + "', '" + name + "', '" + englishname
    + "', '" + age + "', '" + sex + "', '" + birthday
    + "', '" + description + "', '" + createtime + "')"; Connection conn = null;
    Statement stmt = null;
    int rs = 0;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:orcl", "scott",
    "Admin168");
    stmt = conn.createStatement();
    rs = stmt.executeUpdate(sql);
    } catch (Exception e) {
    out.println("(ADD)执行SQL:\"" + sql + "\"时发生异常:"
    + e.getMessage());
    e.printStackTrace();
    return;
    } finally {
    if (stmt != null)
    stmt.close();
    if (conn != null)
    conn.close();
    }
    out.println("<html><style>body{font-size:12px; line-height:25px; }</style><body>");
    out.println(rs + " 条记录被添加到数据库中。");
    out.println("<a href='listperson.jsp'>返回人员列表</a>"); // 将执行的 SQL 语句输出到客户端
    out.println("<br/><br/>执行的 SQL 语句为:<br/>" + sql); return;
    } else if ("del".equals(action)) {
    String[] ids = request.getParameterValues("id");
    if (id == null || ids.length == 0) {
    out.println("没有选中任何行!");
    return;
    }
    String condition = "";
    for (int i = 0; i < ids.length; i++) {
    if (i == 0) {
    condition = "" + ids[i];
    } else {
    condition += "," + ids[i];
    }
    }
    String sql = "delete from person where id in(" + condition
    + ")"; Connection conn = null;
    Statement stmt = null;
    int rs = 0;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:orcl", "scott",
    "Admin168");
    stmt = conn.createStatement();
    rs = stmt.executeUpdate(sql); out.println("<html><style>body{font-size:12px; line-height:25px; }</style><body>");
    out.println(rs + " 条记录被删除。");
    out.println("<a href='listperson.jsp'>返回人员列表</a>"); // 将执行的 SQL 语句输出到客户端
    out.println("<br/><br/>执行的 SQL 语句为:<br/>" + sql); } catch (Exception e) {
    out.println("(DEL)执行SQL\"" + sql + "\"时发生异常:"
    + e.getMessage());
    e.printStackTrace();
    } finally {
    if (stmt != null)
    stmt.close();
    if (conn != null)
    conn.close();
    }
    } else if ("edit".equals(action)) {
    //String id = request.getParameter("id");
    String sql = "select * from person where id=" + id; Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:orcl", "scott",
    "Admin168");
    stmt = conn.createStatement();
    rs = stmt.executeQuery(sql); if (rs.next()) {
    // 有记录 将响应字段从数据库中取出 保存到 request 中,显示到 修改页面
    request.setAttribute("id", rs.getString("id"));
    request.setAttribute("name", rs.getString("name"));
    request.setAttribute("englishname",
    rs.getString("english_name"));
    request.setAttribute("age", rs.getString("age"));
    request.setAttribute("sex", rs.getString("sex"));
    request.setAttribute("birthday",
    rs.getString("birthday"));
    request.setAttribute("description",
    rs.getString("description"));
    request.setAttribute("createtime",
    rs.getString("create_time")); request.setAttribute("action", action); // 转到修改页面
    request.getRequestDispatcher("/addperson.jsp").forward(
    request, response);
    } else {
    // 没有数据 out.println("没有找到 id 为 " + id + " 的记录。");
    } } catch (Exception e) {
    out.println("(EDIT)执行SQL:\"" + sql + "\"时发生异常:"
    + e.getMessage());
    e.printStackTrace();
    } finally {
    if (rs != null)
    rs.close();
    if (stmt != null)
    stmt.close();
    if (conn != null)
    conn.close();
    }
    } else if ("save".equals(action)) {
    String sql = "UPDATE person SET" + " id = '" + id + "', "
    + "name = '" + name + "', " + "englishname = '"
    + englishname + "', " + "sex = '" + sex + "', "
    + "age = '" + age + "', " + "birthday = '" + birthday
    + "', " + "description = '" + description + "', "
    + "createtime = '" + createtime + "', " 
    + "WHERE id =" + id; Connection conn = null;
    Statement stmt = null;
    int rs = 0;
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:orcl", "scott",
    "Admin168");
    stmt = conn.createStatement();
    rs = stmt.executeUpdate(sql);
    if (rs == 0) {
    out.println("影响的数目为0,修改失败!"); } else {
    out.println(rs + "条记录被修改。");
    }
    out.println("<html><style>body{font-size:12px; line-height:25px; }</style><body>");
    out.println("<a href='listperson.jsp'>返回人员列表</a>");
    out.println("<br><br>执行的SQL语句为:<br>" + sql); } catch (Exception e) {
    out.println("(SAVE)执行SQL:\"" + sql + "\"时发生异常:"
    + e.getMessage());
    e.printStackTrace();
    } finally {
    if (stmt != null)
    stmt.close();
    if (conn != null)
    conn.close(); } } else {
    //String id = request.getParameter("id");
    String sql = "UPDATE person SET id = ?, name = ?, english_name = ?, sex = ?, age = ?, birthday = ?, description = ?, createtime = ? WHERE id = ? "; Connection conn = null;
    PreparedStatement preStmt = null; try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:orcl", "scott",
    "Admin168"); preStmt = conn.prepareStatement(sql);
    preStmt.setString(1, id);
    preStmt.setString(2, name);
    preStmt.setString(3, englishname);
    preStmt.setString(4, sex);
    preStmt.setInt(5, Integer.parseInt(age));
    preStmt.setDate(6, new Date(new SimpleDateFormat(
    "yyyy-MM-dd").parse(birthday).getTime()));
    preStmt.setString(7, description);
    preStmt.setDate(8, new Date(new SimpleDateFormat(
    "yyyy-MM-dd").parse(createtime).getTime()));
    //preStmt.setInt(9, Integer.parseInt(id));
    preStmt.setString(9, id); // 使用 preStmt 执行 SQL 语句
    int result = preStmt.executeUpdate(sql); out.println("<html><style>body{font-size:12px; line-height:25px; }</style><body>"); if (result == 0)
    out.println("影响数目为 0, 修改失败. ");
    else
    out.println(result + " 条记录被修改。"); out.println("<a href='listPerson.jsp'>返回人员列表</a>"); // 将执行的 SQL 语句输出到客户端
    out.println("<br/><br/>执行的 SQL 语句为:<br/>" + sql); } catch (SQLException e) {
    out.println("(OTHER)执行SQL:\"" + sql + "\"时发生异常:" + e.getMessage());
    e.printStackTrace();
    } finally {
    if (preStmt != null)
    preStmt.close();
    if (conn != null)
    conn.close();
    }
    }
    %>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
    + request.getServerName() + ":" + request.getServerPort()
    + path + "/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>"><title>My JSP 'operetaperson.jsp' starting page</title><meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    --></head><body></body>
    </html>
      

  2.   

    当执行“新建人员信息”时,出现如下错误
    (ADD)执行SQL:"INSERT INTO PERSON (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('15', '红太狼', 'hongtailang', '4', '女', '2008-04-04', '灰太狼的媳妇', '2012-1-2')"时发生异常:ORA-01861: 文字与格式字符串不匹配当执行“修改”时出现如下错误
    (SAVE)执行SQL:"UPDATE person SET id = '12', name = '灰太狼', englishname = 'huitailang', sex = '男', age = '5', birthday = '2006-05-14 00:00:00.0', description = '红太狼的老公', createtime = '2012-1-2', WHERE id =12"时发生异常:ORA-01747: user.table.column, table.column 或列说明无效 
      

  3.   

    数据库的创建
    CREATE TABLE PERSON 
    (
      ID NUMBER NOT NULL 
    , NAME VARCHAR2(20) NOT NULL 
    , ENGLISH_NAME VARCHAR2(20) NOT NULL 
    , AGE NUMBER NOT NULL 
    , SEX VARCHAR2(20) NOT NULL 
    , BIRTHDAY DATE NOT NULL 
    , DESCRIPTION VARCHAR2(2000) 
    , CREATE_TIME DATE NOT NULL 
    , CONSTRAINT PERSON_PK PRIMARY KEY 
      (
        ID 
      )
      ENABLE 
    );INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('1', '程珂', 'chengke', '33', '男', TO_DATE('1978-08-30', 'YYYY-MM-DD HH24:MI:SS'), '程序人员', TO_DATE('2011-12-29 20:39:45', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('2', '比尔', 'bier', '50', '男', TO_DATE('1970-04-14', 'YYYY-MM-DD HH24:MI:SS'), '清洁工', TO_DATE('2011-12-29 20:41:02', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('3', '孬蛋', 'naodan', '12', '男', TO_DATE('2002-08-06', 'YYYY-MM-DD HH24:MI:SS'), '学生', TO_DATE('2010-12-08 13:47:33', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('4', '小屁孩儿', 'pihaier', '5', '男', TO_DATE('2006-07-30', 'YYYY-MM-DD HH24:MI:SS'), '幼儿园', TO_DATE('2005-04-19 06:49:00', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('5', '小公主', 'queen', '5', '女', TO_DATE('2006-7-30', 'YYYY-MM-DD HH24:MI:SS'), '幼儿园', TO_DATE('2006-07-30 21:17:30', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('6', '爱因斯坦', 'aiyinshitan', '105', '男', TO_DATE('1906-07-07', 'YYYY-MM-DD HH24:MI:SS'), '墓地看守', TO_DATE('2011-12-29 21:19:03', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('7', '吕后', 'lvhou', '2250', '女', TO_DATE('101-03-03', 'YYYY-MM-DD HH24:MI:SS'), '灰飞烟灭', TO_DATE('2001-01-01', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('8', '武则天', 'wuzetian', '750', '女', TO_DATE('863-05-05', 'YYYY-MM-DD HH24:MI:SS'), '上吊', TO_DATE('2002-02-02', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('9', '凤姐', 'fengjie', '25', '女', TO_DATE('1985-04-07', 'YYYY-MM-DD HH24:MI:SS'), '吓死人', TO_DATE('2011-12-29 21:27:14', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('10', '芙蓉姐姐', 'furongjiejie', '28', '女', TO_DATE('1983-06-09', 'YYYY-MM-DD HH24:MI:SS'), '转型中', TO_DATE('2008-08-08', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('11', '喜洋洋', 'xiyangyang', '3', '男', TO_DATE('2008-08-09', 'YYYY-MM-DD HH24:MI:SS'), '超可爱', TO_DATE('2011-12-29 21:29:49', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('12', '灰太狼', 'huitailang', '5', '男', TO_DATE('2006-05-14', 'YYYY-MM-DD HH24:MI:SS'), '精神可嘉', TO_DATE('2010-03-02', 'YYYY-MM-DD HH24:MI:SS'));
    INSERT INTO "SCOTT"."PERSON" (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('13', '懒洋洋', 'lanyangyang', '4', '男', TO_DATE('2007-10-10', 'YYYY-MM-DD HH24:MI:SS'), '懒人中精品', TO_DATE('2008-10-13', 'YYYY-MM-DD HH24:MI:SS'));
      

  4.   

    哦。估计是时间类型的问题。
    楼主试试Oracle的to_date函数,将字符串转换成date类型的数据。
    就是说。sql里面添加to_date函数。
    "INSERT INTO PERSON (ID, NAME, ENGLISH_NAME, AGE, SEX, BIRTHDAY, DESCRIPTION, CREATE_TIME) VALUES ('15', '红太狼', 'hongtailang', '4', '女', to_date('2008-04-04','yyyy-mm-dd'), '灰太狼的媳妇', to_date('2012-1-2','yyyy-mm-dd'))"
      

  5.   


    那放在java中sql语句中因该怎样写呢?String sql = "UPDATE person SET" + " id = '" + id + "', "
                    + "name = '" + name + "', " + "englishname = '"
                    + englishname + "', " + "sex = '" + sex + "', "
                    + "age = '" + age + "', " + "birthday = '" + birthday
                    + "', " + "description = '" + description + "', "
                    + "createtime = '" + createtime + "', " 
                    + "WHERE id =" + id;
      

  6.   

    我刚才把数据库中涉及到Date类型的字段设置为允许非空,然后再添加的时候不添加,“添加人员信息”时没有发生错误,看来还是时间类型的转换出了问题,但是我不会,还请给位继续帮忙
      

  7.   

    现在是执行else {
            //String id = request.getParameter("id");
            String sql = "UPDATE person SET id = ?, name = ?, english_name = ?, sex = ?, age = ?, birthday = ?, description = ?, createtime = ? WHERE id = ? ";        Connection conn = null;
            PreparedStatement preStmt = null;        try {
                Class.forName("oracle.jdbc.driver.OracleDriver");
                conn = DriverManager.getConnection(
                        "jdbc:oracle:thin:@localhost:1521:orcl", "scott",
                        "Admin168");            preStmt = conn.prepareStatement(sql);
                preStmt.setString(1, id);
                preStmt.setString(2, name);
                preStmt.setString(3, englishname);
                preStmt.setString(4, sex);
                preStmt.setInt(5, Integer.parseInt(age));
                preStmt.setDate(6, new Date(new SimpleDateFormat(
                        "yyyy-MM-dd").parse(birthday).getTime()));
                preStmt.setString(7, description);
                preStmt.setDate(8, new Date(new SimpleDateFormat(
                        "yyyy-MM-dd").parse(createtime).getTime()));
                //preStmt.setInt(9, Integer.parseInt(id));
                preStmt.setString(9, id);            // 使用 preStmt 执行 SQL 语句
                int result = preStmt.executeUpdate(sql);            out.println("<html><style>body{font-size:12px; line-height:25px; }</style><body>");            if (result == 0)
                    out.println("影响数目为 0, 修改失败. ");
                else
                    out.println(result + " 条记录被修改。");            out.println("<a href='listPerson.jsp'>返回人员列表</a>");            // 将执行的 SQL 语句输出到客户端
                out.println("<br/><br/>执行的 SQL 语句为:<br/>" + sql);        } catch (SQLException e) {
                out.println("(OTHER)执行SQL:\"" + sql + "\"时发生异常:" + e.getMessage());
                e.printStackTrace();
            } finally {
                if (preStmt != null)
                    preStmt.close();
                if (conn != null)
                    conn.close();
            }
        }出现如下错误
    ORA-01008: 并非所有变量都已绑定 
      

  8.   

    时间类型不匹配请转化:
    Date d = new Date();
    java.sql.Timestamp tst = new java.sql.Timestamp(d.getTime());使用tst即可
      

  9.   


    new Date();出现错误提示
      

  10.   

    CREATE TABLE PERSON 
    (
      ID NUMBER NOT NULL 
    , NAME VARCHAR2(20) NOT NULL 
    , ENGLISH_NAME VARCHAR2(20) NOT NULL 
    , AGE NUMBER NOT NULL 
    , SEX VARCHAR2(20) NOT NULL 
    , BIRTHDAY DATE NOT NULL 
    , DESCRIPTION VARCHAR2(2000) 
    , CREATE_TIME DATE NOT NULL 
    , CONSTRAINT PERSON_PK PRIMARY KEY 
      (
        ID 
      )
      ENABLE 
    );AGE NUMBER NOT NULL 
    类型是NUMBER,'4'的单引号去掉,用4就行了
    确实是垃圾代码,不过都是这么学过来的,初学者能写出来不错了,顶一下
      

  11.   

    UPDATE person SET id = '12', name = '灰太狼', englishname = 'huitailang', sex = '男', age = '5', birthday = '2006-05-14 00:00:00.0', description = '红太狼的老公', createtime = '2012-1-2', WHERE id =12
    改成
    UPDATE person SET id = '12', name = '灰太狼', englishname = 'huitailang', sex = '男', age = 5, birthday = '2006-05-14 00:00:00.0', description = '红太狼的老公', createtime = '2012-1-2', WHERE id =12
    也是AGE值单引号的问题,写程序前把自己拼的sql去数据库执行一下,很容易发现问题的
      

  12.   

    为什么要把java代码写在jsp里面
      

  13.   

    你新增和修改传给oracle的时间都是'2008-04-04'String类型,对应数据库的varchar之类。oracle与sqlserver不同,传入时间不能传入String。请转换为date(数据库的)