数据库问题
古月书斋 2004-05-06 01:04:56 小弟写了一个JAVABEAB:package bookship;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.io.*;
import java.sql.Date;
public class UserRegist implements Serializable {
private UserBean userInfo;
private Connection con;
public UserRegist() {
}
public void setUserInfo(UserBean userInfo)
{
this.userInfo=userInfo;
//得到用户信息;
}
public void setConnnectoin(Connection con)
{
this.con=con;
}
public void regist()throws Exception
{ if(con==null)
return;
String reg="insert into user_info values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
try
{
PreparedStatement pstmt=con.prepareStatement(reg);
pstmt.setString(1,"2");
pstmt.setString(2,"2");
pstmt.setString(3,"3");
pstmt.setString(4,"2");
pstmt.setString(5,"5");
pstmt.setString(6,"4");
pstmt.setString(7,"7");
pstmt.setString(8,"8");
pstmt.setString(9,"9");
pstmt.setInt(10,1);
pstmt.setInt(11,0);
pstmt.setDate(12,new java.sql.Date(new java.util.Date().getTime()));
pstmt.setInt(13,1);
pstmt.setInt(14,0);
pstmt.setString(15,"12");
pstmt.setString(16,"13");
pstmt.executeUpdate();
con.close();
}
catch(Exception e)
{ con.close();
e.printStackTrace();
throw e;
}
}
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
}
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
}
}
我用.jsp测试不成功.<%@ page contentType="text/html; charset=GBK" import="bookship.*,java.sql.*"%>
<html>
<head>
title>用户信息注册页面</title>
</head>
<jsp:useBean id="dataBean" scope="session" class="bookship.DatabaseBean" />
<jsp:useBean id="UserInfo" scope="session" class="bookship.UserBean" />
<jsp:setProperty name="UserInfo" property="*" />
<jsp:useBean id="regist" scope="session" class="bookship.UserRegist" />
<LINK href="hellking.css" type=text/css rel=stylesheet>
<body><%
regist.setUserInfo(UserInfo);
regist.setConnnectoin(dataBean.getConnection());
regist.regist();
<a href="main.jsp">返回</a>
</body>
</html>
我通过测试dataBean.getConnection()没有问题.