package cc.openhome.model;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
public class BlahDAOJdbcImpl implements BlahDAO {
private DataSource dataSource;
public BlahDAOJdbcImpl(DataSource dataSource){
this.dataSource=dataSource;
}
@Override
public List<Blah> getBlahs(Blah blah) {
// TODO Auto-generated method stub
Connection conn=null;
PreparedStatement stmt=null;
SQLException ex=null;
List<Blah> blahs=null;
try{
conn=dataSource.getConnection();
stmt=conn.prepareStatement("select date,txt from t_blah where name=?");
stmt.setString(1, blah.getUsername());
ResultSet rs=stmt.executeQuery();
blahs=new ArrayList<Blah>();
while(rs.next()){
blahs.add(new Blah(blah.getUsername(),rs.getTimestamp(1),rs.getString(2)));
}
}catch(SQLException e){
ex=e;
}finally{
if(stmt!=null){
try{
stmt.close();
}catch(SQLException e){
if(ex==null)
ex=e;
}
}
if(conn!=null){
try{
conn.close();
}catch(SQLException e){
if(ex==null)
ex=e;
}
}
if(ex!=null)
throw new RuntimeException(ex);
}
return blahs;
}
@Override
public void addBlah(Blah blah) {
// TODO Auto-generated method stub
Connection conn=null;
PreparedStatement stmt=null;
SQLException ex=null;
try{
conn=dataSource.getConnection();
stmt=conn.prepareStatement("insert into t_blah(name,date,txt) values(?,?,?)");
stmt.setString(1,blah.getUsername());
stmt.setTimestamp(2, new Timestamp(blah.getDate().getTime()));
stmt.setString(3, blah.getTxt());
stmt.executeUpdate();
}catch(SQLException e){
ex=e;
}finally{
if(stmt!=null){
try{
stmt.close();
}catch(SQLException e){
if(ex==null)
ex=e;
}
}
if(conn!=null){
try{
conn.close();
}catch(SQLException e){
if(ex==null)
ex=e;
}
}
if(ex!=null)
throw new RuntimeException(ex);
}
}
@Override
public void deleteBlah(Blah blah) {
// TODO Auto-generated method stub
Connection conn=null;
PreparedStatement stmt=null;
SQLException ex=null;
try{
conn=dataSource.getConnection();
stmt=conn.prepareStatement("delete from t_blah where date=?");
stmt.setTimestamp(1,new Timestamp(blah.getDate().getTime()));
stmt.executeUpdate();
}catch(SQLException e){
ex=e;
}finally{
if(stmt!=null){
try{
stmt.close();
}catch(SQLException e){
if(ex==null)
ex=e;
}
}
if(conn!=null){
try{
conn.close();
}catch(SQLException e){
if(ex==null)
ex=e;
}
}
if(ex!=null)
throw new RuntimeException(ex);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Jsp&Servlet学习笔记中的完整范例Gossip
共59个文件
class:15个
java:14个
jsp:7个
5星 · 超过95%的资源 需积分: 10 8 下载量 139 浏览量
2015-08-30
14:42:30
上传
评论 1
收藏 1.48MB RAR 举报
温馨提示
Jsp&Servlet完整范例Gossip,已经整合完成,各项功能可用,很适合初学者,采用Model2架构!
资源推荐
资源详情
资源评论
收起资源包目录
Gossip.rar (59个子文件)
Gossip
.project 1KB
WebContent
WEB-INF
lib
jstl.jar 20KB
commons-lang3-3.4.jar 424KB
standard.jar 384KB
mysql-connector-java-5.1.16-bin.jar 768KB
tags
blahs.tag 1KB
web.xml 479B
jsp
user.jsp 1004B
register.jsp 1KB
error.jsp 640B
index.jsp 2KB
success.jsp 437B
member.jsp 1KB
images
123.jpg 5KB
META-INF
MANIFEST.MF 39B
context.xml 403B
css
index.css 298B
member.css 318B
NewFile.html 152B
test.jsp 605B
gossip 441B
src
cc
openhome
model
BlahDAOJdbcImpl.java 3KB
Account.java 720B
AccountDAO.java 187B
UserService.java 2KB
AccountDAOjdbcImpl.java 3KB
BlahDAO.java 180B
Blah.java 693B
DatabaseBean.java 779B
controller
logout.java 964B
login.java 2KB
delete.java 1KB
message.java 2KB
register.java 2KB
web
GossipListener.java 1KB
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 345B
org.eclipse.jdt.core.prefs 364B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.component 470B
.jsdtscope 503B
gossip.sql 505B
build
classes
cc
openhome
model
UserService$DateComparator.class 1KB
Account.class 1KB
UserService.class 3KB
BlahDAO.class 337B
Blah.class 1KB
BlahDAOJdbcImpl.class 5KB
DatabaseBean.class 1KB
AccountDAO.class 310B
AccountDAOjdbcImpl.class 4KB
controller
delete.class 2KB
login.class 3KB
logout.class 1KB
register.class 4KB
message.class 3KB
web
GossipListener.class 2KB
gossip.sql.bak 505B
.classpath 841B
共 59 条
- 1
资源评论
- Tabuyos2017-11-18挺不错的资料,谢谢分享.
Semantic_smq
- 粉丝: 3
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功