网站建设资讯

NEWS

网站建设资讯

Java小项目之:相亲网站,来一起非诚勿扰!

Java小项目之:相亲网站,来一起非诚勿扰!
今天给大家分享的java小项目是一个做非常有意思的网站,相亲网站。有前台系统和后台管理系统。
部分代码展示:
package dao;

创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、网站建设、外贸网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的夏河网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import util.DBUtil;
import entity.User;

public class UserDAO {
public List list() throws Exception{
List users =
new ArrayList();
Connection conn = DBUtil.getConnection();
Statement stat = conn.createStatement();
ResultSet rst = stat.executeQuery("select from friend_user2");
while(rst.next()){
User user = new User(rst.getString("username"),
rst.getString("password"),rst.getString("name"),
rst.getInt("age"),rst.getString("gender"),
rst.getString("phone"));
user.setId(rst.getLong("id"));
users.add(user);
}
DBUtil.close(conn);
return users;
}
public long save(User user) throws Exception{
long id = -1;
Connection conn = DBUtil.getConnection();
PreparedStatement prep =
conn.prepareStatement(
"insert into friend_user2(username,password,name,age,gender,phone) " +
"values(?,?,?,?,?,?)",java.sql.Statement.RETURN_GENERATED_KEYS);
prep.setString(1, user.getUsername());
prep.setString(2, user.getPwd());
prep.setString(3, user.getName());
prep.setInt(4,user.getAge());
prep.setString(5, user.getGender());
prep.setString(6, user.getPhone());
prep.executeUpdate();
ResultSet rst = prep.getGeneratedKeys();
if(rst.next()){
id = rst.getLong(1);
}
DBUtil.close(conn);
return id;
}
public User findByUsername(String username) throws Exception{
User user = null;
Connection conn = DBUtil.getConnection();
PreparedStatement prep =
conn.prepareStatement("select
from friend_user2 where username=?");
prep.setString(1, username);
ResultSet rst = prep.executeQuery();
if(rst.next()){
user = new User(rst.getString("username"),
rst.getString("password"),rst.getString("name"),
rst.getInt("age"),rst.getString("gender"),
rst.getString("phone"));
user.setId(rst.getLong("id"));
}
DBUtil.close(conn);
return user;
}
public User findById(Long id) throws Exception{
User user = null;
Connection conn = DBUtil.getConnection();
PreparedStatement prep =
conn.prepareStatement(
"select * from friend_user2 where id =?");
prep.setLong(1, id);
ResultSet rst = prep.executeQuery();
if(rst.next()){
user = new User(rst.getString("username"),
rst.getString("password"),rst.getString("name"),
rst.getInt("age"),rst.getString("gender"),
rst.getString("phone"));
user.setId(id);
}
DBUtil.close(conn);
return user;
}
}
喜欢这样文章的可以关注我,我会持续更新,你们的关注是我更新的动力!需要更多java学习资料的也可以私信我!
祝关注我的人都:身体健康,财源广进,福如东海,寿比南山,早生贵子,从不掉发!
Java小项目之:相亲网站,来一起非诚勿扰!


文章标题:Java小项目之:相亲网站,来一起非诚勿扰!
当前URL:http://cdweb.net/article/isjipi.html