package com.my.struts.model;
import java.sql.*;
import com.my.struts.db.*;
public class FriendInfoDAO {
Connection con=null;
Statement stmt=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
ConDB db=null;
public FriendInfoDAO()
{
}
//查询是否存在指定好朋友:根据朋友姓名查询,得到查询结果是布尔型
public boolean search(String friendName)
{
boolean result=false;
try
{
db=new ConDB();
String sql="select * from friendInfo where name=?";
con=db.getConnection();
pstmt=con.prepareStatement(sql);
pstmt.setString(1, friendName);
rs=pstmt.executeQuery();
if(rs.next())
{
result=true;
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(rs!=null) rs.close();
if(pstmt!=null) pstmt.close();
if(con!=null) con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
return result;
}
public boolean insert(String friendName,String phone,String address)
{
boolean result=false;
try
{
String sql="insert friendInfo values(?,?,?)";
db=new ConDB();
con=db.getConnection();
pstmt=con.prepareStatement(sql);
pstmt.setString(1,friendName);
pstmt.setString(2,phone);
pstmt.setString(3,address);
int i=pstmt.executeUpdate();
if(i>0)
{
result=true;
}
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(pstmt!=null) pstmt.close();
if(con!=null) con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
return result;
}
public String display(String sql)
{
StringBuffer st=new StringBuffer();
try
{
db=new ConDB();
con=db.getConnection();
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
st.append("<table border='1' width='60%' align='center'>");
st.append("<th>FriendName</th>");
st.append("<th>Phone</th>");
st.append("<th>Address</th>");
while(rs.next())
{
st.append("<tr>");
String friendName=rs.getString("name");
String phone=rs.getString("phone");
String address=rs.getString("address");
st.append("<td>");
st.append(friendName);
st.append("</td>");
st.append("<td>");
st.append(phone);
st.append("</td>");
st.append("<td>");
st.append(address);
st.append("</td>");
st.append("</tr>");
}
st.append("</table>");
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
if(con!=null) con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
System.out.println("st="+st);
return st.toString();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
addressBook.rar (60个子文件)
addressBook
src
com
my
struts
model
FriendInfoDAO.java 3KB
User.java 423B
UserLogin.java 855B
form
SearchForm.java 2KB
LogonForm.java 1KB
InsertForm.java 1KB
db
ConDB.java 423B
action
LogonOff.java 436B
DisplayAll.java 606B
InsertAction.java 1KB
SearchAction.java 2KB
LogonAction.java 1KB
yourcompany
struts
ApplicationResources.properties 645B
.classpath 1KB
.mystrutsdata 262B
.mymetadata 306B
.myeclipse
.project 1KB
数据库
addressBook 979KB
WebRoot
META-INF
MANIFEST.MF 39B
index.jsp 337B
login.jsp 584B
confirmaction.jsp 293B
mainMenu.jsp 569B
userRight.jsp 230B
insert.jsp 560B
display.jsp 393B
search.jsp 573B
WEB-INF
classes
com
my
struts
model
UserLogin.class 2KB
User.class 763B
FriendInfoDAO.class 4KB
form
SearchForm.class 2KB
InsertForm.class 2KB
LogonForm.class 2KB
db
ConDB.class 857B
action
DisplayAll.class 1KB
InsertAction.class 2KB
SearchAction.class 3KB
LogonAction.class 2KB
LogonOff.class 1KB
yourcompany
struts
ApplicationResources.properties 645B
struts-config.xml 2KB
struts-tiles.tld 8KB
struts-template.tld 2KB
validator-rules.xml 41KB
.struts-config.mex 4KB
lib
commons-lang.jar 53KB
commons-logging.jar 27KB
struts-legacy.jar 9KB
jakarta-oro.jar 62KB
commons-validator.jar 40KB
struts.jar 428KB
commons-beanutils.jar 100KB
commons-collections.jar 160KB
commons-fileupload.jar 19KB
commons-digester.jar 96KB
struts-bean.tld 9KB
struts-html.tld 65KB
struts-logic.tld 14KB
struts-nested.tld 63KB
web.xml 1KB
共 60 条
- 1
资源评论
- zhangjunhe312012-12-12数据库文件不对。
- 夜雨流年2012-08-29数据库文件打不开啊
- scnustar2011-10-18小项目,对于刚入门的同学还是有些帮助的
- a359467292012-11-20对于我这个入门来说真的挺有用的。
lingswp
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功