Compare commits
3 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
160ba34359 | 2 years ago |
|
|
83acb8d9cb | 2 years ago |
|
|
de158c53d3 | 2 years ago |
@ -0,0 +1,75 @@
|
||||
package com.jwz.javaBean;
|
||||
|
||||
public class Accountjwz {
|
||||
String useridjwz;
|
||||
String passwordjwz;
|
||||
String emailjwz;
|
||||
String usernamejwz;
|
||||
String addressjwz;
|
||||
String cityjwz;
|
||||
String countryjwz;
|
||||
String phonenumjwz;
|
||||
public Accountjwz() {
|
||||
}
|
||||
public Accountjwz (String useridjwz,String passwordjwz,String emailjwz,String usernamejwz,String addressjwz,String cityjwz,String countryjwz,String phonenumjwz){
|
||||
this.useridjwz=useridjwz;
|
||||
this.passwordjwz=passwordjwz;
|
||||
this.emailjwz=emailjwz;
|
||||
this.usernamejwz=usernamejwz;
|
||||
this.addressjwz=addressjwz;
|
||||
this.cityjwz=cityjwz;
|
||||
this.countryjwz=countryjwz;
|
||||
this.phonenumjwz=phonenumjwz;
|
||||
}
|
||||
public String getuseridjwz(){
|
||||
return useridjwz;
|
||||
}
|
||||
public void setuseridjwz(String useridjwz){
|
||||
this.useridjwz=useridjwz;
|
||||
}
|
||||
public String getpasswordjwz(){
|
||||
return passwordjwz;
|
||||
}
|
||||
public void setpasswordjwz(String passwordjwz){
|
||||
this.passwordjwz=passwordjwz;
|
||||
}
|
||||
public String getemailjwz(){
|
||||
return emailjwz;
|
||||
}
|
||||
public void setemailjwz(String emailjwz){
|
||||
this.emailjwz=emailjwz;
|
||||
}
|
||||
public String getusernamejwz(){
|
||||
return usernamejwz;
|
||||
}
|
||||
public void setusernamejwz(String usernamejwz){
|
||||
this.usernamejwz=usernamejwz;
|
||||
}
|
||||
public String getaddressjwz(){
|
||||
return addressjwz;
|
||||
}
|
||||
public void setaddressjwz(String addressjwz){
|
||||
this.addressjwz=addressjwz;
|
||||
}
|
||||
public String getcityjwz(){
|
||||
return cityjwz;
|
||||
}
|
||||
public void setcityjwz(String cityjwz){
|
||||
this.cityjwz=cityjwz;
|
||||
}
|
||||
public String getcountryjwz(){
|
||||
return countryjwz;
|
||||
}
|
||||
public void setcountryjwz(String countryjwz){
|
||||
this.countryjwz=countryjwz;
|
||||
}
|
||||
public String getphonenumjwz(){
|
||||
return phonenumjwz;
|
||||
}
|
||||
public void setphonenumjwz(String phonenumjwz){
|
||||
this.phonenumjwz=phonenumjwz;
|
||||
}
|
||||
public String toString() {
|
||||
return this.usernamejwz+"来自"+this.addressjwz;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package com.jwz.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.jwz.javaBean.*;
|
||||
|
||||
public interface AccountjwzDao{
|
||||
public Accountjwz findByUseridjwz(String useridjwz);
|
||||
public void insert(Accountjwz accountjwz);
|
||||
public ArrayList<Accountjwz> findAll();
|
||||
public int updateAccountjwz(Accountjwz accountjwz);
|
||||
public int deleteAccountjwz(String useridjwz);
|
||||
}
|
||||
@ -0,0 +1,175 @@
|
||||
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("---------------------------");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue