JSP复习笔记——第10章 连接数据库 之 使用JSP+DAO完成用户登陆
使用JSP+DAO完成用户登陆
Java代码
1.import java.sql.* ;
2.
3.public class DataBaseConnection {
4. private String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
5. private String DBURL = "jdbc:oracle:thin:@localhost:1521:sky" ;
6. private String DBUSER = "scott" ;
7. private String DBPASSWORD = "darkness" ;
8. private Connection conn = null ;
9.
10. public DataBaseConnection() {
11. try {
12. Class.forName(DBDRIVER) ;
13. this.conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
14. } catch (Exception e) {
15. }
16. }
17.
18. public Connection getConnection() {
19. return this.conn ;
20. }
21.
22. public void close() {
23. try {
24. this.conn.close() ;
25. }
26. catch (Exception e) {
27. }
28. }
29.};
import java.sql.* ;
public class DataBaseConnection {
private String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
private String DBURL = "jdbc:oracle:thin:@localhost:1521:sky" ;
private String DBUSER = "scott" ;
private String DBPASSWORD = "darkness" ;
private Connection conn = null ;
public DataBaseConnection() {
try {
Class.forName(DBDRIVER) ;
this.conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
} catch (Exception e) {
}
}
public Connection getConnection() {
return this.conn ;
}
public void close() {
try {
this.conn.close() ;
}
catch (Exception e) {
}
}
};
--------------------------PersonVO.java---------------
Java代码
1.package org.darkness.vo;
2.
3.public class PersonVO {
4.private String id;
5.private String name;
6.private String password;
7.// getter and setter 方法
8.}
9.------------------------PersonDAO.java-------------
10.package org.darkness.dao;
11.public interface PersonDAO{
12. boolean isLogin(PersonVO pv);
13.}
14.------------------------PersonDAOImpl.java-----------
15.package org.darkness.daoimpl;
16.public class PersonDAOImpl implements PersonDAO {
17. public boolean isLogin(PersonVO pv){
18. boolean flag = false;