日期:2014-05-17 浏览次数:20772 次
package shopping.Object;
import java.sql.*;
import shopping.util.*;
public class User {
private int id;
private String username;
private String password;
private String phone;
private String addr;
private Timestamp rdate;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public Timestamp getRdate() {
return rdate;
}
public void setRdate(Timestamp rdate) {
this.rdate = rdate;
}
public void save()
{
Connection conn=null;
PreparedStatement pstmt=null;
try {
String sql="insert into ruser values(1,?,?,?,?,?)";
conn = DB.getConn();
if(conn!=null&&sql!=null)
{
pstmt=DB.getPstmt(conn,sql);
pstmt.setString(1,username);
pstmt.setString(2,password);
pstmt.setString(3,phone);
pstmt.setString(4,addr);
pstmt.setTimestamp(5,rdate);
pstmt.executeUpdate();
}
} catch (Exception e) {
e.printStackTrace();
}finally
{
if(pstmt!=null)
{
DB.closeStatement(pstmt);
pstmt=null;
}
if(conn!=null)
{
DB.closeConn(conn);
conn=null;
}
}
}
}
package shopping.util;
import java.sql.*;
public class DB {
static
{
try {
Class.forName("Oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConn()
{
Connection conn=null;
try {
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "scott", "124567");
} catch (Exception e) {
}
return conn;
}
public static void closeConn(Connection conn)
{
try {
if(conn!=null)
conn.close();
conn=null;
} catch (SQLException e) {
e.printStackTrace();
}
}
public static Statement getStatement(Connection conn)
{
Statemen