新手求救,会员更改资料页面的DAO
刚刚接触JSP,对servlet不是很熟,哪位大神能给一个会员更新资料页面的DAO ,请尽量写的简单详细一些,小弟感激不尽。例如打开会员更新页面读取会员的一些基本信息,用户可以进行更新资料操作。谢谢!
--------------------编程问答-------------------- 你要纯 jdbc 的 dao,还是 mybatis 或者 hibernate 的?这里有个 jdbc 的:
public class DAOFactory {--------------------编程问答--------------------
private static final SessionFactory sessionFacotory;
// 定义一个TrheadLocal .
static Session currentSession().....
public UserDao getUserDAO() { return new UserDaoImpl(sesssion);}
pulbic OtherDao getOtherDAO() { return new OtherDaoImpl(session);}
......
}
public inte易做图ce UserDao {
public insertUser(FormBean)
public updateUser(FormBean);
}
然后就实现DAO的接口: (Struts的FormBean...VO来的..)
public class UserDaoImpl implements UserDao {
private Session session;
public UserDaoImpl(Session session){
this.session = session;
}...
public insertUser(FormBean) {
..//..
session.save(UserPO);
..//..
return FormBean;
}
public FormBean updateUser(FormBean) {
..//..
session.update(UserPO);
..//..
return FormBean;
}
}
最后定义你的PO:
public class UserPO {
String firstname, lastname, password..........
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class Hi {
public void insert() {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
String username = "system";
String password = "oracle";
Connection conn = DriverManager.getConnection(url, username, password);
String insertSql = "update test set name = ? where id = ?";
PreparedStatement ps = conn.prepareStatement(insertSql);
ps.setString(1, "liu");
ps.setString(2, "00120013");
ps.execute();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void main(String args[]){
Hi hi = new Hi();
hi.insert();
}
}
jdbc连接数据库
补充:Java , Web 开发