You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
5.6 KiB
176 lines
5.6 KiB
package com.jwz.dao.impl;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.DriverManager;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.Statement;
|
|
import java.util.ArrayList;
|
|
|
|
import com.jwz.dao.AccountjwzDao;
|
|
import com.jwz.javaBean.Accountjwz;
|
|
|
|
public class AccountjwzImpl implements AccountjwzDao {
|
|
|
|
@Override
|
|
public Accountjwz findByUseridjwz(String useridjwz) {
|
|
// TODO 自动生成的方法存根
|
|
Accountjwz acjwz=new Accountjwz();
|
|
try {
|
|
Connection connjwz = JDBCUtil.getConnection();
|
|
String sqljwz ="select *from account where userid=?";
|
|
PreparedStatement prestmjwz=connjwz.prepareStatement(sqljwz);
|
|
prestmjwz.setString(1,useridjwz);
|
|
ResultSet rsjwz=prestmjwz.executeQuery();
|
|
while(rsjwz.next()) {
|
|
Accountjwz account=new Accountjwz();
|
|
account.setuseridjwz(rsjwz.getString("userid"));
|
|
account.setusernamejwz(rsjwz.getString("username"));
|
|
account.setpasswordjwz(rsjwz.getString("password"));
|
|
account.setaddressjwz(rsjwz.getString("address"));
|
|
account.setcityjwz(rsjwz.getString("city"));
|
|
account.setcountryjwz(rsjwz.getString("country"));
|
|
account.setphonenumjwz(rsjwz.getString("phonenum"));
|
|
account.setemailjwz(rsjwz.getString("email"));
|
|
acjwz=account;
|
|
}
|
|
rsjwz.close();
|
|
prestmjwz.close();
|
|
connjwz.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return acjwz;
|
|
}
|
|
|
|
@Override
|
|
public void insert(Accountjwz accountjwz) {
|
|
// TODO 自动生成的方法存根
|
|
try {
|
|
Connection connjwz = JDBCUtil.getConnection();
|
|
String sqljwz ="Insert into account (userid,username,password,address,city,country,phonenum,email) values(?,?,?,?,?,?,?,?)";
|
|
PreparedStatement prestmjwz=connjwz.prepareStatement(sqljwz);
|
|
prestmjwz.setString(1,accountjwz.getuseridjwz());
|
|
prestmjwz.setString(2,accountjwz.getusernamejwz());
|
|
prestmjwz.setString(3,accountjwz.getpasswordjwz());
|
|
prestmjwz.setString(4,accountjwz.getaddressjwz());
|
|
prestmjwz.setString(5,accountjwz.getcityjwz());
|
|
prestmjwz.setString(6,accountjwz.getcountryjwz());
|
|
prestmjwz.setString(7,accountjwz.getphonenumjwz());
|
|
prestmjwz.setString(8,accountjwz.getemailjwz());
|
|
prestmjwz.executeUpdate();
|
|
prestmjwz.close();
|
|
connjwz.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ArrayList<Accountjwz> findAll() {
|
|
ArrayList<Accountjwz> accounts=new ArrayList<Accountjwz>();
|
|
try {
|
|
Connection connjwz = JDBCUtil.getConnection();
|
|
|
|
String sqljwz ="select *from account";
|
|
Statement stsjwz =connjwz.createStatement();
|
|
ResultSet rsjwz=stsjwz.executeQuery(sqljwz);
|
|
|
|
while(rsjwz.next()) {
|
|
Accountjwz account=new Accountjwz();
|
|
account.setuseridjwz(rsjwz.getString("userid"));
|
|
account.setusernamejwz(rsjwz.getString("username"));
|
|
account.setpasswordjwz(rsjwz.getString("password"));
|
|
account.setaddressjwz(rsjwz.getString("address"));
|
|
account.setcityjwz(rsjwz.getString("city"));
|
|
account.setcountryjwz(rsjwz.getString("country"));
|
|
account.setphonenumjwz(rsjwz.getString("phonenum"));
|
|
account.setemailjwz(rsjwz.getString("email"));
|
|
accounts.add(account);
|
|
}
|
|
rsjwz.close();
|
|
stsjwz.close();
|
|
connjwz.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
// TODO 自动生成的方法存根
|
|
return accounts;
|
|
}
|
|
|
|
@Override
|
|
public int updateAccountjwz(Accountjwz accountjwz) {
|
|
// TODO 自动生成的方法存根
|
|
try {
|
|
Connection connjwz = JDBCUtil.getConnection();
|
|
|
|
String sqljwz ="update account set username=?,address=? where userid=?";
|
|
PreparedStatement prestmjwz=connjwz.prepareStatement(sqljwz);
|
|
prestmjwz.setString(1,accountjwz.getusernamejwz());
|
|
prestmjwz.setString(2,accountjwz.getaddressjwz());
|
|
prestmjwz.setString(3,accountjwz.getuseridjwz());
|
|
prestmjwz.executeUpdate();
|
|
prestmjwz.close();
|
|
connjwz.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
@Override
|
|
public int deleteAccountjwz(String useridjwz) {
|
|
// TODO 自动生成的方法存根
|
|
int flagjwz=0;
|
|
try {
|
|
Connection connjwz = JDBCUtil.getConnection();
|
|
String sqljwz ="delete from account where userid=?";
|
|
PreparedStatement prestmjwz=connjwz.prepareStatement(sqljwz);
|
|
prestmjwz.setString(1, useridjwz);
|
|
flagjwz = prestmjwz.executeUpdate();
|
|
prestmjwz.close();
|
|
connjwz.close();
|
|
}
|
|
catch(Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return flagjwz;
|
|
}
|
|
public static void main(String[] args) {
|
|
AccountjwzImpl acjwz =new AccountjwzImpl();
|
|
for(Accountjwz al : acjwz.findAll()) {
|
|
System.out.print(al);
|
|
System.out.println("");
|
|
System.out.println("---------------------------");
|
|
}
|
|
System.out.println(acjwz.findByUseridjwz("1"));
|
|
System.out.println("---------------------------");
|
|
Accountjwz a1jwz=new Accountjwz("2","123","123","xh","zj","123","cn","123");
|
|
acjwz.updateAccountjwz(a1jwz);
|
|
for(Accountjwz al : acjwz.findAll()) {
|
|
System.out.print(al);
|
|
System.out.println("");
|
|
System.out.println("---------------------------");
|
|
}
|
|
System.out.println(acjwz.deleteAccountjwz("2"));
|
|
System.out.println("---------------------------");
|
|
for(Accountjwz al : acjwz.findAll()) {
|
|
System.out.print(al);
|
|
System.out.println("");
|
|
System.out.println("---------------------------");
|
|
}
|
|
Accountjwz a2jwz=new Accountjwz("3","123","123","xl","zj","123","cn","123");
|
|
acjwz.insert(a2jwz);
|
|
for(Accountjwz al : acjwz.findAll()) {
|
|
System.out.print(al);
|
|
System.out.println("");
|
|
System.out.println("---------------------------");
|
|
}
|
|
}
|
|
}
|