MySQL數(shù)據(jù)庫(kù)

select tu.tuname,zhe.name from zhe inner join tu on zhe.number=tu.number where zhe.age<(select avg(age) from zhe);

IMG_0790.JPG
IMG_0791.JPG
IMG_0792.JPG
IMG_0793.JPG
IMG_0794.JPG

數(shù)據(jù)庫(kù)做增刪改查
可以下載mysql-connector-java-5.0.8-bin.jar包操作

package jinchenrui;

import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;
import java.util.Scanner;

public class text {
    static String string=null;
    static String string2=null;
    static String string3=null;
    static String string4=null;
static{
     string = ResourceBundle.getBundle("db").getString("driver");
     string2 = ResourceBundle.getBundle("db").getString("url");
     string3 = ResourceBundle.getBundle("db").getString("name");
     string4 = ResourceBundle.getBundle("db").getString("paw"); 
}
static Connection connection=null;
public static void main(String[] args) throws Exception {
    
    try {
        Class.forName(string);
         connection = DriverManager.getConnection(string2,string3,string4);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    
    System.out.println("1添加2修改3查看4刪除");
    int a=new Scanner(System.in).nextInt();
    switch(a){
    
    case 1:
        insert();   
        break;
    
    case 2:
        updata();
        break;
    case 3:
    select();
    break;
    case 4:
        delete();
    }
    
    
    
    
    
}
private static void delete() throws Exception {
    // TODO Auto-generated method stub
    Statement createStatement = connection.createStatement();
    String dele="delete from User where Name='王五'";
    createStatement.executeUpdate(dele);
    createStatement.close();
    connection.close();
    
}
private static void select() throws SQLException {
    // TODO Auto-generated method stub
    Statement createStatement = connection.createStatement();
    String kk="select * from User";
    ResultSet query = createStatement.executeQuery(kk);
    while(query.next()){
        int int1 = query.getInt("Id");
        String string5 = query.getString("Name");
        String string6 = query.getString("Pwd");
        String string7 = query.getString("Email");
        Date date = query.getDate("Birthday");
        System.out.println("編號(hào)是"+int1+"姓名是"+string5+"密碼是"+string6+"郵箱是"+string7+"生日是"+date);
    }
    query.close();
    createStatement.close();
    connection.close();
    
    


}
private static void updata() throws Exception {
    // TODO Auto-generated method stub
    Statement statement = connection.createStatement();
    String lisi="update User set Pwd=9999 where Name='李四'";
    statement.executeUpdate(lisi);
    statement.close();
    connection.close();
    
}
private static void insert() throws Exception {
    // TODO Auto-generated method stub
    Statement statement = connection.createStatement();
    String insert="insert into User values(null,'張三','6666','zhangshan@163.com',19991021)";
    String insert2="insert into User values(null,'李四','7777','lisi@163.com',19980808)";
    String insert3="insert into User values(null,'王五','8888','wangwu@123.com',19970701)";
    statement.addBatch(insert);
    statement.addBatch(insert2);
    statement.addBatch(insert3);
    int[] is = statement.executeBatch();
    statement.close();
    connection.close();
}






}

db.properties

driver=com.mysql.jdbc.Driver
url=jdbc\:mysql\://localhost\:3306/2017db
name=root
paw=502900588

無(wú)人售貨車

package Database;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java.util.ResourceBundle;

public class ADO {
    public static String Driver;
    public static String url;
    public static String user;
    public static String password;

    //  獲取配置文件方法一
    //  1.創(chuàng)建properties對(duì)象
    //  Properties properties = new Properties();
    //  2.加載配置
    //  FileInputStream inputStream = new FileInputStream("db.properties");//前面加xxx/是代表那個(gè)目錄下
    //  properties.load(inputStream);
    //  3.獲取配置文件里面的字段
    //  String Driver = properties.getProperty("Driver");
    //  String user = properties.getProperty("user");
    //  String url = properties.getProperty("url");
    //  String password = properties.getProperty("password");
    //  System.out.println(Driver+password);
    //  獲取配置文件方法二

    //  static{
    //   Driver = ResourceBundle.getBundle("db").getString("Driver");//沒(méi)有后綴明
    //     url = ResourceBundle.getBundle("db").getString("url");
    //   user = ResourceBundle.getBundle("db").getString("user");
    //     password = ResourceBundle.getBundle("db").getString("password");
    //  System.out.println(Driver);
    //  
    //  }

    //  數(shù)據(jù)庫(kù)工具
    public static Connection conn() {
        Properties properties = new Properties();
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream("src/db.properties");
        } catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        try {
            properties.load(inputStream);
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        String Driver = properties.getProperty("Driver");
        String user = properties.getProperty("user");
        String url = properties.getProperty("url");
        String password = properties.getProperty("password");
//      System.out.println(Driver + password);

        Connection connection = null ;
        try {
            Class.forName(Driver);
            connection = DriverManager.getConnection(url, user, password);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return connection;

    }

    public static void closeConnection(Statement stat, Connection conn){

        if (stat != null) {
            try {
                stat.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }

}

package Database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import java.util.Scanner;

import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.Default;
public class data {
    static Statement statement2=null;
    static Scanner scanner=null;
    static String name=null;
public static void choice() throws Exception  {
    
    //數(shù)據(jù)庫(kù)進(jìn)去
    //表進(jìn)去
    //表記錄
    
        Connection connection = ADO.conn();
         statement2 = connection.createStatement();
     scanner = new Scanner(System.in);
     boolean b=true;
    while(b){
        System.out.println("管理商品:0,查看訂單 1,新建,2,查看,3,刪除,4,修改,5關(guān)閉");
        int a=scanner.nextInt();
        switch(a){
        case 0:
            System.out.println("1,查看全部訂單 2,查看單個(gè)訂單");
            int kk=scanner.nextInt();
            if(kk==1){
            String nn=" select * from yan y inner join yan2 y2 on y.id=y2.wuping_id inner join enter y1 on y2.ren_id=y1.id;";
            
            ResultSet query1 = statement2.executeQuery(nn);
            while (query1.next()) {
                String string2 = query1.getString("user");
                String string3 = query1.getString("password");
                int int1 = query1.getInt("id");
                String name = query1.getString("name");
                int price=query1.getInt("price");
                int int2 = query1.getInt("liang");
                String string = query1.getString("leixing");
                System.out.println("訂單名:"+string2+"\t訂單密碼:"+string3+"\t購(gòu)買商品編號(hào):"+int1+"\t商品:"+name+"\t價(jià)格:"+price+"\t數(shù)量:"+int2+"\t類型:"+string);
            }query1.close();
            }else if(kk==2){
                System.out.println("請(qǐng)輸入單號(hào)名");
                String next = scanner.next();
                 String hh="select * from yan where id in(select wuping_id from yan2 where ren_id in(select id from enter where user='"+next+"'));";
                 ResultSet query11 = statement2.executeQuery(hh);
                    while (query11.next()) {
                        int int1 = query11.getInt("id");
                        String name = query11.getString("name");
                        int price1=query11.getInt("price");
                        int int21 = query11.getInt("liang");
                        String string1 = query11.getString("leixing");
                        System.out.println("編號(hào):"+int1+"\t商品:"+name+"\t價(jià)格:"+price1+"\t數(shù)量:"+int21+"\t類型:"+string1);

                } query11.close();
                    ResultSet query111 = statement2.executeQuery(hh);//在另建一個(gè)
                    if(query111.next()){
                
                }else{
                    System.out.println("沒(méi)有訂單");
                }query111.close();
                    
            }
            break;
        case 1:
            System.out.println("請(qǐng)按格式輸入(添加)內(nèi)容");
            System.out.println("請(qǐng)輸入商品名");
            String no=scanner.next();
            System.out.println("請(qǐng)輸入商品價(jià)格");
            int add=scanner.nextInt();
            System.out.println("請(qǐng)輸入商品數(shù)量");
            int bdd=scanner.nextInt();
            System.out.println("請(qǐng)輸入商品類型");
            String cdd=scanner.next();
            String ak47="insert into yan values(null,?,?,?,?);";
            PreparedStatement statement = connection.prepareStatement(ak47);
            statement.setString(1, no);
            statement.setInt(2, add);
            statement.setInt(3, bdd);
            statement.setString(4, cdd);
            int j = statement.executeUpdate();
            if(j==1){
            System.out.println("添加成功");
            }else{
            System.out.println("添加失敗"); 
            }
            
            break;
        case 2:
            System.out.println("1,查詢所有商品 2,查詢單個(gè)商品");
            int as=scanner.nextInt();
            if(as==1){
            String yes="select * from yan";
            ResultSet query = statement2.executeQuery(yes);
            while (query.next()) {
                int int1 = query.getInt("id");
                String name = query.getString("name");
                int price=query.getInt("price");
                int int2 = query.getInt("liang");
                String string = query.getString("leixing");
                System.out.println("編號(hào):"+int1+"\t商品:"+name+"\t價(jià)格:"+price+"\t數(shù)量:"+int2+"\t類型:"+string);
            }query.close();
            }else{
                System.out.println("請(qǐng)輸入商品名");
                String shu1=scanner.next();
                String yes="select * from yan where name='"+shu1+"'";
                ResultSet query = statement2.executeQuery(yes);
                if (query.next()) {
                    int int1 = query.getInt("id");
                    String name = query.getString("name");
                    int price=query.getInt("price");
                    int int2 = query.getInt("liang");
                    String string = query.getString("leixing");
                    System.out.println("編號(hào)"+int1+"\t商品"+name+"\t價(jià)格"+price+"\t數(shù)量"+int2+"\t類型"+string);
                }else{
                    System.out.println("沒(méi)有此商品");
                }query.close();
                
            }
            break;
        case 3:
            System.out.println("請(qǐng)輸入(刪除)商品名");
            String no0=scanner.nextLine();
            String no2=scanner.nextLine();
            String delete="delete from yan where name='"+no2+"'";
            int i = statement2.executeUpdate(delete);
            System.out.println("修改"+i+"個(gè)");
            break;
        case 4:
            System.out.println("請(qǐng)選擇修改名:1,商品名 2,價(jià)格 3,數(shù)量 4,類型 ");
            int xuan=scanner.nextInt();
            switch(xuan){
            case 1:
                 name="name";
                xuan();
                break;
            case 2:
                name="price";
                xuannumber();
                break;
            case 3:
                name="liang";
                xuannumberliang();
                break;
            case 4:
                name="leixing";
                xuan1();
                break;
            default:
                System.out.println("請(qǐng)選擇1-4");
                break;
                
            }
            
            
            break;
        case 5:
            try {
                ADO.closeConnection(statement2, connection);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            b=false;
            System.out.println("推出菜單");
        
            break;
        default:
            System.out.println("請(qǐng)輸入1-5(*^_^*)");
            break;
            
            
        }
    }

    
}

private static void xuannumberliang() throws Exception {
    // TODO Auto-generated method stub
    System.out.println("請(qǐng)選擇:[1,商品名 2,商品id] 來(lái)修改商品數(shù)量");
    int xuan=scanner.nextInt();
    // TODO Auto-generated method stub
    if(xuan==1){
        String name1="name";
        System.out.println("請(qǐng)輸入商品名");
//      String set00=scanner.next();
        String set11=scanner.next();
        System.out.println("請(qǐng)輸入修改后的值");
        int set222=scanner.nextInt();
        String set55="update yan set "+name+"="+set222+" where "+name1+"='"+set11+"'";
        int i = statement2.executeUpdate(set55);
        System.out.println("修改"+i+"個(gè)");
    }
    else if(xuan==2){
        
    String name2="id";
    System.out.println("請(qǐng)輸入編號(hào)");
//  String set00=scanner.next();
    int set11=scanner.nextInt();
    System.out.println("請(qǐng)輸入修改后的值");
    int set222=scanner.nextInt();
    String set55="update yan set "+name+"="+set222+" where "+name2+"="+set11+"";
    int i = statement2.executeUpdate(set55);
    System.out.println("修改"+i+"個(gè)");
    }else{
        System.out.println("輸入錯(cuò)誤");
    }
    
}

private static void xuan1() throws Exception {
    System.out.println("請(qǐng)選擇:[1,商品名 2,商品id] 來(lái)修改商品類型");
    int xuan=scanner.nextInt();
    // TODO Auto-generated method stub
    if(xuan==1){
        String name1="name";
        System.out.println("請(qǐng)輸入商品名");
//      String set00=scanner.next();
        String set11=scanner.next();
        System.out.println("請(qǐng)輸入修改后的值");
        String set222=scanner.next();
        String set55="update yan set "+name+"='"+set222+"' where "+name1+"='"+set11+"'";
        int i = statement2.executeUpdate(set55);
        System.out.println("修改"+i+"個(gè)");
    }
    if(xuan==2){
        
    String name2="id";
    System.out.println("請(qǐng)輸入編號(hào)");
//  String set00=scanner.next();
    int set11=scanner.nextInt();
    System.out.println("請(qǐng)輸入修改后的值");
    String set222=scanner.next();
    String set55="update yan set "+name+"='"+set222+"' where "+name2+"="+set11+"";
    int i = statement2.executeUpdate(set55);
    System.out.println("修改"+i+"個(gè)");
    }else 
        if(xuan!=1&&xuan!=2){
            System.out.println("輸入錯(cuò)誤");
        }//?
}


private static void xuannumber() throws Exception {
    System.out.println("請(qǐng)選擇:[1,商品名 2,商品id] 來(lái)修改商品價(jià)格");
    int xuan=scanner.nextInt();
    // TODO Auto-generated method stub
    if(xuan==1){
        String name1="name";
        System.out.println("請(qǐng)輸入商品名");
//      String set00=scanner.next();
        String set11=scanner.next();
        System.out.println("請(qǐng)輸入修改后的值");
        int set222=scanner.nextInt();
        String set55="update yan set "+name+"="+set222+" where "+name1+"='"+set11+"'";
        int i = statement2.executeUpdate(set55);
        System.out.println("修改"+i+"個(gè)");
    }else 
        
        if(xuan==2){

    String name2="id";
    System.out.println("請(qǐng)輸入編號(hào)");
//  String set00=scanner.next();
    int set11=scanner.nextInt();
    System.out.println("請(qǐng)輸入修改后的值");
    int set222=scanner.nextInt();
    String set55="update yan set "+name+"="+set222+" where "+name2+"="+set11+"";
    int i = statement2.executeUpdate(set55);
    System.out.println("修改"+i+"個(gè)");
    }
    else 
    if(xuan!=1&&xuan!=2){
                System.out.println("輸入錯(cuò)誤");
            }//?
}

private static void xuan() throws Exception {
    
    // TODO Auto-generated method stub
    System.out.println("請(qǐng)輸入修改前的值");
    String set0=scanner.nextLine();
    String set1=scanner.nextLine();
    System.out.println("請(qǐng)輸入修改后的值");
    String set22=scanner.nextLine();
    String set="update yan set "+name+"='"+set22+"' where "+name+"='"+set1+"'";
    int i = statement2.executeUpdate(set);
    System.out.println("修改"+i+"個(gè)");
}
}

package Database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class password {
    public  static int int1;
    public static String name1;

    public static void Enter() throws Exception{
        Connection conn = ADO.conn();//注冊(cè)驅(qū)動(dòng)并連接
        
        Statement statement = conn.createStatement();//執(zhí)行注冊(cè)
        
        while(true){
            System.out.println("歡迎來(lái)到無(wú)人商店:1,注冊(cè) 2,登陸 3,管理員登陸 4,關(guān)閉");
        int a = new Scanner(System.in).nextInt();
    switch(a){
    case 1:
        System.out.println("請(qǐng)輸入注冊(cè)的用戶名");
        name1 = new Scanner(System.in).next();
        System.out.println("請(qǐng)輸入密碼");
        int pwd1 = new Scanner(System.in).nextInt();
        String sq2="insert into enter values(null,'"+name1+"',"+pwd1+")";
        String sq3="select * from enter where user='"+name1+"' and  password="+pwd1;
        int executeUpdate = statement.executeUpdate(sq2);
        ResultSet query = statement.executeQuery(sq3);
        if(query.next()){//----------------------------
        int1 = query.getInt("id");
        }query.close();
        String diang="insert into yan2 values("+int1+",null)";
        int executeUpdate2 = statement.executeUpdate(diang);
        if(executeUpdate==1&&executeUpdate2==1){
            System.out.println("添加成功");
        }else{
            System.out.println("失敗了請(qǐng)重試");
//          String sq4="delete from enter where user='"+name1+"'";
//           statement.executeUpdate(sq4);
        }
        break;
    case 2:
        System.out.println("請(qǐng)輸入用戶名");
        String name = new Scanner(System.in).next();
        System.out.println("請(qǐng)輸入密碼:");
        int pwd = new Scanner(System.in).nextInt();
        String sql="select * from enter where user=? and password=?";
        PreparedStatement statement2 = conn.prepareStatement(sql);
        statement2.setString(1, name);
        statement2.setInt(2, pwd);
        ResultSet set = statement2.executeQuery();
        if (set.next()) {
            System.out.println("登錄成功!");
            String s3="select * from enter where user='"+name+"' and  password="+pwd;
            ResultSet q9ry = statement.executeQuery(s3);
            if(q9ry.next()){
            int1 = q9ry.getInt("id");
            }
            String s4="select * from enter where id="+int1;
            ResultSet r11y = statement.executeQuery(s4);
            if(r11y.next()){
                name1 = r11y.getString("user");
            }
            
            
            try {
                user.user1();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            System.out.println("用戶名和密碼不匹配!");
        }
        set.close();
        statement2.close();
        break;
    case 3:
        System.out.println("請(qǐng)輸入管理員賬號(hào)");
        int name3 = new Scanner(System.in).nextInt();
        System.out.println("請(qǐng)輸入密碼:");
        int pwd3 = new Scanner(System.in).nextInt();
        String sql3="select * from guan where z="+name3+" and y= "+pwd3;
        ResultSet ret3 = statement.executeQuery(sql3);
        if (ret3.next()) {
            System.out.println("登錄成功!");
            try {
                data.choice();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            System.out.println("用戶名和密碼不匹配!");
        }
        ret3.close();
        break;
    case 4:
        
        System.out.println("拜拜");
        ADO.closeConnection(statement, conn);
        System.exit(0);
        break;
    default:
        System.out.println("請(qǐng)輸入1-4(*^_^*)");
        break;
    }
    
}}}

開啟

package Database;

public class text {
public static void main(String[] args) {
    try {
        password.Enter();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
    
}
}

package Database;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class user {
    static Scanner scanner=null;
public static void user1() throws Exception{
    Connection conn = ADO.conn();
    Statement statement2 = conn.createStatement();
     scanner = new Scanner(System.in);
     boolean b=true;
     while(b){
         System.out.println("歡迎請(qǐng)選擇:0,查看商品 1,購(gòu)買 2,刪除(不要) 3,查看我的訂單 4,結(jié)賬 5,推出");
         int a=scanner.nextInt();
         switch(a){
         case 0:
                System.out.println("1,查詢所有2,查詢單個(gè)商品");
                int as=scanner.nextInt();
                if(as==1){
                String yes="select * from yan";
                ResultSet query = statement2.executeQuery(yes);
                while (query.next()) {
                    int int1 = query.getInt("id");
                    String name = query.getString("name");
                    int price=query.getInt("price");
                    int int2 = query.getInt("liang");
                    String string = query.getString("leixing");
                    System.out.println("編號(hào):"+int1+"\t商品"+name+"\t價(jià)格:"+price+"\t數(shù)量:"+int2+"\t類型:"+string);
                }
                }else{
                    System.out.println("請(qǐng)輸入商品名");
                    String shu=scanner.next();
                    String yes="select * from yan where name='"+shu+"'";
                    ResultSet query = statement2.executeQuery(yes);
                    if (query.next()) {
                        int int1 = query.getInt("id");
                        String name = query.getString("name");
                        int price=query.getInt("price");
                        int int2 = query.getInt("liang");
                        String string = query.getString("leixing");
                        System.out.println("編號(hào):"+int1+"\t商品:"+name+"\t價(jià)格:"+price+"\t數(shù)量:"+int2+"\t類型:"+string);
                    }else{
                        System.out.println("沒(méi)有此商品");
                    }
                    
                }
                break;
         case 1:
             int int110=0;
             boolean m=true;
             while(m){
                 conn.setAutoCommit(false);
                 System.out.println("請(qǐng)輸入商品名");
                 String shu=scanner.next();
                String yes="select * from yan where name='"+shu+"'";
                    ResultSet query = statement2.executeQuery(yes);
                    while(query.next()){
                    int110 = query.getInt("id");
                    String name = query.getString("name");
                    int price=query.getInt("price");
                    int int2 = query.getInt("liang");
                    String string = query.getString("leixing");
                    System.out.println("編號(hào):"+int110+"\t商品:"+name+"\t價(jià)格:"+price+"\t數(shù)量:"+int2+"\t類型:"+string);
//                  String liang="up";
//                  怎么把liang進(jìn)行加和減
                    System.out.println("購(gòu)買成功");
                    }
                    String shang="insert into yan2 values("+password.int1+","+int110+")";
                    statement2.executeUpdate(shang);
                    ResultSet query12 = statement2.executeQuery(yes);
                     conn.commit();
                    if (query12.next()) {
                }else{
                    System.out.println("沒(méi)有此商品");
                }
            System.out.println("是否繼續(xù)購(gòu)買?");
            String xuan=scanner.next();
            if(xuan.equals("否")){
                m=false;
                System.out.println("好的ok");
            }}
            
             break;
         case 2:
             conn.setAutoCommit(false);
             System.out.println("請(qǐng)輸入商品名");
             String shu=scanner.next();
             String yes="select * from yan where name='"+shu+"'";
             ResultSet query = statement2.executeQuery(yes);
                if (query.next()) {
                    int int1 = query.getInt("id");
                    String yes2="delete from yan2 where wuping_id="+int1;
                    int i = statement2.executeUpdate(yes2);
                    System.out.println("刪除"+i+"個(gè)");
                }else{
                    System.out.println("沒(méi)有此商品");
                }
             conn.commit();
            break;
         case 3:
             System.out.println("查看訂單");
             String hh="select * from yan where id in(select wuping_id from yan2 where ren_id in(select id from enter where user='"+password.name1+"'));";
//                      select * from yan where id in(select wuping_id from yan2 where ren_id in(select id from enter where user='           我     '));

             ResultSet query1 = statement2.executeQuery(hh);
             if(query1.next()){
                 int int1 = query1.getInt("id");
                    String name = query1.getString("name");
                    int price=query1.getInt("price");
                    int int2 = query1.getInt("liang");
                    String string = query1.getString("leixing");
                    System.out.println("編號(hào)"+int1+"商品"+name+"價(jià)格"+price+"數(shù)量"+int2+"類型"+string);
                while (query1.next()) {
                    int llmm = query1.getInt("id");
                    String nanme = query1.getString("name");
                    int priee=query1.getInt("price");
                    int intoo2 = query1.getInt("liang");
                    String strijjng = query1.getString("leixing");
                    System.out.println("編號(hào)"+llmm+"商品"+nanme+"價(jià)格"+priee+"數(shù)量"+intoo2+"類型"+strijjng);
                }}
             else{
                    
                 System.out.println("沒(méi)有訂單");
                 
             }
             
             break;
         case 4:
             System.out.println("結(jié)賬了哦");
             String mm=" select sum(price) from yan where id in(select wuping_id from yan2 where ren_id in(select id from enter where user='"+password.name1+"'));";
             ResultSet query2 = statement2.executeQuery(mm);
             if(query2.next()){
                 int int1 = query2.getInt("sum(price)");
                 System.out.println("商品總價(jià)是:"+int1);
                 System.out.println("走出門口自動(dòng)結(jié)賬");
             }else{
                 System.out.println("購(gòu)物車空空如也");
             }
             break;
         case 5:
             ADO.closeConnection(statement2, conn);
             System.out.println("歡迎下次購(gòu)買(*^_^*)");
             b=false;
             break;
         }
         
         
         
     }
}
}

db.properties

Driver=com.mysql.jdbc.Driver
url=jdbc\:mysql\://localhost\:3306/data
user=root
password=502900588
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末虐译,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子吴趴,更是在濱河造成了極大的恐慌漆诽,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,723評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件锣枝,死亡現(xiàn)場(chǎng)離奇詭異厢拭,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)撇叁,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,485評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門供鸠,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人陨闹,你說(shuō)我怎么就攤上這事楞捂。” “怎么了趋厉?”我有些...
    開封第一講書人閱讀 152,998評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵寨闹,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我觅廓,道長(zhǎng),這世上最難降的妖魔是什么涵但? 我笑而不...
    開封第一講書人閱讀 55,323評(píng)論 1 279
  • 正文 為了忘掉前任杈绸,我火速辦了婚禮帖蔓,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘瞳脓。我一直安慰自己塑娇,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,355評(píng)論 5 374
  • 文/花漫 我一把揭開白布劫侧。 她就那樣靜靜地躺著埋酬,像睡著了一般。 火紅的嫁衣襯著肌膚如雪烧栋。 梳的紋絲不亂的頭發(fā)上写妥,一...
    開封第一講書人閱讀 49,079評(píng)論 1 285
  • 那天,我揣著相機(jī)與錄音审姓,去河邊找鬼珍特。 笑死,一個(gè)胖子當(dāng)著我的面吹牛魔吐,可吹牛的內(nèi)容都是我干的扎筒。 我是一名探鬼主播,決...
    沈念sama閱讀 38,389評(píng)論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼酬姆,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼嗜桌!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起辞色,我...
    開封第一講書人閱讀 37,019評(píng)論 0 259
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤骨宠,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后淫僻,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體诱篷,經(jīng)...
    沈念sama閱讀 43,519評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,971評(píng)論 2 325
  • 正文 我和宋清朗相戀三年雳灵,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了棕所。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,100評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡悯辙,死狀恐怖琳省,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情躲撰,我是刑警寧澤针贬,帶...
    沈念sama閱讀 33,738評(píng)論 4 324
  • 正文 年R本政府宣布,位于F島的核電站拢蛋,受9級(jí)特大地震影響桦他,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜谆棱,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,293評(píng)論 3 307
  • 文/蒙蒙 一快压、第九天 我趴在偏房一處隱蔽的房頂上張望圆仔。 院中可真熱鬧,春花似錦蔫劣、人聲如沸坪郭。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,289評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)歪沃。三九已至,卻和暖如春嫌松,著一層夾襖步出監(jiān)牢的瞬間沪曙,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,517評(píng)論 1 262
  • 我被黑心中介騙來(lái)泰國(guó)打工豆瘫, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留珊蟀,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,547評(píng)論 2 354
  • 正文 我出身青樓外驱,卻偏偏與公主長(zhǎng)得像育灸,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子昵宇,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,834評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容