package com.tools;
import java.sql.*;
import java.io.*;
import java.util.*;
public class ConnDB {
public Connection conn = null;
public Statement stmt = null;
public ResultSet rs = null;
private static String propFileName = "/com/connDB.properties"; //指定资源文件保存的位置
private static Properties prop = new Properties();
private static String dbClassName =
"com.microsoft.jdbc.sqlserver.SQLServerDriver";
private static String dbUrl =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_shop";
private static String dbUser = "sa";
private static String dbPwd = "";
public ConnDB(){
try {
InputStream in=getClass().getResourceAsStream(propFileName);
prop.load(in); //通过输入流对象加载Properties文件
dbClassName = prop.getProperty("DB_CLASS_NAME"); //获取数据库驱动
dbUrl = prop.getProperty("DB_URL",dbUrl);
dbUser=prop.getProperty("DB_USER",dbUser);
dbPwd=prop.getProperty("DB_PWD",dbPwd);
}
catch (Exception e) {
e.printStackTrace(); //输出异常信息
}
}
public static Connection getConnection() {
Connection conn = null;
try {
Class.forName(dbClassName).newInstance();
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
}
catch (Exception ee) {
ee.printStackTrace();
}
if (conn == null) {
System.err.println(
"警告: DbConnectionManager.getConnection() 获得数据库链接失败.\r\n\r\n链接类型:" +
dbClassName + "\r\n链接位置:" + dbUrl + "\r\n用户/密码" + dbUser + "/" +
dbPwd);
}
return conn;
}
/*
*功能:执行查询语句
*/
public ResultSet executeQuery(String sql) {
try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);
}
catch (SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}
/*
*功能:执行更新操作
*/
public int executeUpdate(String sql) {
int result = 0;
try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
result = stmt.executeUpdate(sql);
}catch (SQLException ex) {
result = 0;
}
try {
stmt.close();
}catch (SQLException ex1) {
}
return result;
}
public int executeUpdate_id(String sql) {
int result = 0;
try {
conn = getConnection();
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
result = stmt.executeUpdate(sql);
String ID = "select @@IDENTITY as id";
rs = stmt.executeQuery(ID);
if (rs.next()) {
int autoID = rs.getInt("id");
result = autoID;
}
}
catch (SQLException ex) {
result = 0;
}
return result;
}
/*
*功能:关闭数据库的连接
*/
public void close() {
try { //捕捉异常
if (rs != null) { //当ResultSet对象的实例rs不为空时
rs.close(); //关闭ResultSet对象
}
if (stmt != null) { //当Statement对象的实例stmt不为空时
stmt.close(); //关闭Statement对象
}
if (conn != null) { //当Connection对象的实例conn不为空时
conn.close(); //关闭Connection对象
}
} catch (Exception e) {
e.printStackTrace(System.err); //输出异常信息
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
jsp 实例代码 shopcenter实例
共272个文件
gif:104个
jsp:68个
jpg:43个
需积分: 0 35 下载量 18 浏览量
2009-04-01
21:05:17
上传
评论 1
收藏 1.94MB RAR 举报
温馨提示
本资源是一个JSP的实例,内部包括了详细的代码和使用说明
资源详情
资源评论
资源推荐
收起资源包目录
jsp 实例代码 shopcenter实例 (272个子文件)
牙刷.bmp 64KB
zwtp.bmp 58KB
水杯.bmp 21KB
ConnDB.class 4KB
MemberDaoImpl.class 3KB
Member.class 3KB
GoodsDaoImpl.class 3KB
Goods.class 2KB
SubtypeDaoImpl.class 1KB
PlacardDaoImpl.class 1KB
SuperTypeDaoImpl.class 1KB
ChStr.class 1KB
SubType.class 832B
Placard.class 807B
SuperType.class 623B
Goodselement.class 338B
MemberDao.class 261B
GoodsDao.class 179B
SupertypeDao.class 157B
SubtypeDao.class 151B
PlacardDao.class 151B
style.css 3KB
Thumbs.db 142KB
Thumbs.db 83KB
Thumbs.db 6KB
程序使用说明.doc 48KB
manage_03.gif 24KB
manage_center_goodsdetail.gif 19KB
manage_center_goodsmodi.gif 19KB
manage_center_superAdd.gif 19KB
manage_center_subList.gif 19KB
manage_center_orderdetail.gif 19KB
manage_center_subAdd.gif 19KB
manage_center_goodsdel.gif 19KB
manage_center_superList.gif 19KB
manage_center_memberdetail.gif 19KB
manage_center_placardadd.gif 19KB
manage_center_goodsadd.gif 19KB
manage_center_memberlist.gif 19KB
manage_center_orderlist.gif 18KB
manage_center_placardlist.gif 18KB
ad1.gif 12KB
ggzs_blue.gif 10KB
ggzs_green.gif 10KB
cart.gif 9KB
tel.GIF 9KB
ggzs.gif 8KB
ad2.gif 8KB
sub_bbsDetail.gif 7KB
sub_searchResult.gif 7KB
center_newgoods.gif 7KB
shop_28.gif 7KB
shop_18.gif 7KB
sub_checkout.gif 7KB
sub_memberModify.gif 7KB
sub_sale.gif 7KB
sub_goodsDetail.gif 6KB
center_goodsTypeList.gif 6KB
ad3.gif 6KB
friendLink.GIF 6KB
sub_cartSee.gif 6KB
sub_sellSort.gif 6KB
sub_newgoods.gif 6KB
shop_33.gif 6KB
sub_register.gif 6KB
sub_order.gif 5KB
left_type.gif 5KB
shop_22.gif 4KB
manage_rightTitle.GIF 3KB
btn_long.gif 2KB
btn_login_long.gif 2KB
sign.GIF 2KB
btn_login_ok.gif 2KB
btn_buy.GIF 2KB
btn_short.gif 2KB
btn_detail.GIF 2KB
btn_return.GIF 2KB
shop_21.gif 2KB
btn_manageLogin.gif 1KB
login_ico.GIF 1KB
contact.GIF 1KB
jia.gif 1KB
shop_26.gif 1KB
jian_null.gif 1KB
modify.gif 1KB
del.gif 1KB
manage_rightKbottom.GIF 1KB
manage_rightKtop.GIF 1KB
shop_27.gif 895B
manage_06.gif 864B
center02.gif 814B
jian.gif 746B
shop_24.gif 601B
enforce.gif 567B
thaw.gif 536B
folder.gif 533B
shop_31.gif 469B
btn_search.gif 467B
manage_leftTitle_right.GIF 415B
manage_leftTitle_left.GIF 408B
共 272 条
- 1
- 2
- 3
liulin063326
- 粉丝: 2
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
- 基于MIC+NE555光敏电阻的声光控电路Multisim仿真原理图
- 基于JSP毕业设计-基于WEB操作系统课程教学网站的设计与实现(源代码+论文).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0