package shujuku.Junit.com;
import java.sql.*;
public class DBBean {
Connection conn=null;
ResultSet rs=null;
public int executeQuery(String sql){// select
rs=null;
try{
conn=DBContext.getConnection();
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}catch(Exception e){
e.printStackTrace();
}
int k=0;
try {
while(rs.next()){
k++;
}
} catch (SQLException e) {
e.printStackTrace();
}
closeConnection();
return k;
}
public int executeInsert(News news){
try{
conn=DBContext.getConnection();
String sql = "insert into news(id,title,kind)" +
"values(?,?,?)";
PreparedStatement stmt= conn.prepareStatement(sql);
stmt.setInt(1, news.getId());
stmt.setString(2,news.getTitle());
stmt.setString(3, news.getKind());
int i=stmt.executeUpdate();
closeConnection();
return i;
}catch(Exception e){
e.printStackTrace();
return -1;
}
}
public int executeDelete(int id){
try{
conn=DBContext.getConnection();
String sql = "delete from news where id=?" ;
PreparedStatement stmt= conn.prepareStatement(sql);
stmt.setInt(1,id);
int i=stmt.executeUpdate();
closeConnection();
return i;
}catch(Exception e){
e.printStackTrace();
return -1;
}
}
public int executeDelete(String title){
try{
conn=DBContext.getConnection();
String sql = "delete from news where title =?";
PreparedStatement stmt= conn.prepareStatement(sql);
stmt.setString(1, title);
int i=stmt.executeUpdate();
closeConnection();
return i;
}catch(Exception e){
e.printStackTrace();
return -1;
}
}
public News findById(int id) {
News news = null;
try {
conn=DBContext.getConnection();
String sql = "select * from news where id=?";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setInt(1, id);
ResultSet rs = pst.executeQuery();
if(rs.next()) {
news = myNews(rs);
}
rs.close();
pst.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
return news;
}
private News myNews(ResultSet rs) throws SQLException {
News news = new News();
news.setId(rs.getInt("id"));
news.setTitle(rs.getString("title"));
news.setKind(rs.getString("kind"));
return news;
}
public void closeConnection(){
try{
if(!conn.isClosed()) conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
测试驱动程序
共40个文件
class:24个
java:8个
classpath:3个
4星 · 超过85%的资源 需积分: 10 5 下载量 166 浏览量
2008-07-08
11:48:38
上传
评论
收藏 26KB RAR 举报
温馨提示
这是我的毕业设计。。做的是基于JAVA的测试驱动开发的研究与应用。。希望对大家有所帮助。。
资源推荐
资源详情
资源评论
收起资源包目录
shujukuJunit.rar (40个子文件)
shujukuJunit
bin
META-INF
MANIFEST.MF 25B
shujuku
Junit
com
DBBean.class 3KB
News.class 901B
DBContextTest.class 923B
DeleteFromDB.class 729B
DeleteFromDBTest.class 777B
AddToDBTest.class 1KB
AddToDB.class 2KB
DBContext.class 1KB
.project 382B
Junit
datest
com
.classpath 411B
src
META-INF
MANIFEST.MF 25B
shujuku
Junit
com
NewsGateWay.class 294B
DBBean.java 2KB
DBContext.java 614B
NewsListTest.class 1KB
DBBean.class 1KB
News.class 966B
AddToDBTest.java 584B
DBContextTest.class 850B
NewsList.class 952B
AddToDB.java 830B
In.class 2KB
News.java 503B
DBContextTest.java 574B
DeleteFromDB.java 359B
Find.class 3KB
Delete.class 2KB
DBBeanTest.class 1KB
DBContext.class 1KB
DeleteFromDBTest.java 379B
.project 382B
Junit
datest
com
ArrayList.class 438B
NewsTest.class 358B
News.class 964B
NewsGetWay.class 2KB
DBContext.class 1KB
.classpath 411B
.project 388B
.classpath 478B
共 40 条
- 1
资源评论
- 懵霸2012-10-07测试程序还不错。可以参考
- jianddc2014-03-31还行吧,虽然跟我要进行的项目不搭,但还是不错的。
zhuonewb
- 粉丝: 12
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功