资源简介
简单jsp动态页面源代码
实现页面操作对数据库的增删改查
特别简单化,适合初学者查看!
代码片段和文件信息
package com.hr.dao;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Properties;
public class baseDao {
String driver;
String url;
String user;
String password;
private Connection conn;
private ResultSet rs;
private PreparedStatement pst;
private Statement st;
public baseDao() {
super();
init();
}
public void init() {
Properties p = new Properties();// ����һ�����������ļ��ļ�
File path=new File(baseDao.class.getClassLoader().getResource(“/“).getFile()“dbConfig.properties“);
try {
// ����һ���ļ������������ڶ�ȡ�ļ�
FileInputStream fis = new FileInputStream(path);
p.load(fis);// �����ļ�
this.driver = p.getProperty(“driver“);// ��ݼ�ֵ��ϵ��ȡֵ
this.url = p.getProperty(“url“);
this.user = p.getProperty(“user“);
this.password = p.getProperty(“password“);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Connection getConn() {
try {
Class.forName(driver);
this.conn = DriverManager.getConnection(url user password);
System.out.println(“数据库连接成功“ + this.conn.toString());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
System.out.println(“未找到驱动“);
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println(“SQL语句不正确!“);
e.printStackTrace();
}
return this.conn;
}
public ResultSet getRs(String sql) {
if (this.conn == null) {
this.getConn();
}
try {
st = conn.createStatement();
this.rs = st.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return this.rs;
}
public int getUpdate(String sql) {
if (this.conn == null) {
this.getConn();
}
int result = 0;
try {
st = conn.createStatement();
result = st.executeUpdate(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
public ResultSet getRs(String sql object[] para) {
if (this.conn == null) {
this.getConn();
}
try {
pst = conn.prepareStatement(sql);
for (int i = 0; i < para.length; i++) {
pst.setobject(i + 1 para[i]);
}
this.rs = pst.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return this.rs;
}
public int getUpdate(String sql object[] para) {
if (this.conn == null) {
this.getConn();
}
int result = 0;
try {
pst = conn.prepareStatement(sql);
for (int i = 0; i < para.length; i++) {
pst.setobject(i + 1 para[i]);
}
result = pst.executeUpdate();
} catch (SQLException e) {
// TODO
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-08-25 17:15 ServletTry\
文件 529 2015-08-24 09:11 ServletTry\.classpath
目录 0 2015-08-25 17:16 ServletTry\.myeclipse\
文件 303 2015-08-24 09:11 ServletTry\.myme
文件 1753 2015-08-24 09:16 ServletTry\.project
目录 0 2015-08-25 17:15 ServletTry\.settings\
文件 500 2015-08-24 09:11 ServletTry\.settings\.jsdtscope
文件 88 2015-08-24 09:11 ServletTry\.settings\org.eclipse.core.resources.prefs
文件 395 2015-08-24 09:11 ServletTry\.settings\org.eclipse.jdt.core.prefs
文件 468 2015-08-24 09:11 ServletTry\.settings\org.eclipse.wst.common.component
文件 252 2015-08-24 09:11 ServletTry\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2015-08-24 09:11 ServletTry\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2015-08-24 09:11 ServletTry\.settings\org.eclipse.wst.jsdt.ui.superType.name
目录 0 2015-08-25 17:15 ServletTry\WebRoot\
目录 0 2015-08-25 17:15 ServletTry\WebRoot\me
文件 36 2015-08-24 09:11 ServletTry\WebRoot\me
目录 0 2015-08-25 17:15 ServletTry\WebRoot\WEB-INF\
目录 0 2015-08-25 17:15 ServletTry\WebRoot\WEB-INF\classes\
目录 0 2015-08-25 17:15 ServletTry\WebRoot\WEB-INF\classes\com\
目录 0 2015-08-25 17:15 ServletTry\WebRoot\WEB-INF\classes\com\hr\
目录 0 2015-08-25 17:15 ServletTry\WebRoot\WEB-INF\classes\com\hr\dao\
文件 5589 2015-08-24 15:39 ServletTry\WebRoot\WEB-INF\classes\com\hr\dao\ba
文件 1009 2015-08-24 09:15 ServletTry\WebRoot\WEB-INF\classes\com\hr\dao\CustomeDao.class
文件 7196 2015-08-24 18:00 ServletTry\WebRoot\WEB-INF\classes\com\hr\dao\CustomeDaoImp.class
文件 1154 2015-08-24 10:27 ServletTry\WebRoot\WEB-INF\classes\com\hr\dao\filter.class
目录 0 2015-08-25 17:15 ServletTry\WebRoot\WEB-INF\classes\com\hr\entity\
文件 3058 2015-08-24 09:15 ServletTry\WebRoot\WEB-INF\classes\com\hr\entity\Customes.class
目录 0 2015-08-25 17:15 ServletTry\WebRoot\WEB-INF\classes\com\hr\myServlet\
文件 7333 2015-08-25 09:15 ServletTry\WebRoot\WEB-INF\classes\com\hr\myServlet\UserServlet.class
文件 3170 2015-08-24 09:15 ServletTry\WebRoot\WEB-INF\classes\com\hr\myServlet\UserServlet2.class
目录 0 2015-08-25 17:15 ServletTry\WebRoot\WEB-INF\classes\com\hr\test\
............此处省略29个文件信息
评论
共有 条评论