1.码云GIT提交

2.设计思路

1,使用数据库对购物车的数据进行处理

2.分别使用sql语句来实现对购物车和商城物品的增删改查。

3.代码

package Main;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import java.awt.FlowLayout;

import javax.swing.JTextField;

import java.awt.Color;

import javax.swing.JButton;

import javax.swing.SwingConstants;

import javax.swing.JLabel;

import java.awt.Font;

import java.awt.Frame;

import javax.swing.BoxLayout;

import java.awt.GridBagLayout;

import java.awt.GridLayout;

import com.jgoodies.forms.layout.FormLayout;

import com.jgoodies.forms.layout.ColumnSpec;

import com.jgoodies.forms.layout.RowSpec;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import javax.swing.event.ChangeListener;

import javax.swing.event.ChangeEvent;

public class Fframe extends JFrame {

private JTextField textField;

private JTextField textField_1;

private JPanel contentPane;

private JPanel contentPane1;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

Fframe frame = new Fframe();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the frame.

*/

public Fframe() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 432, 376);

contentPane = new JPanel();

contentPane.setForeground(Color.BLUE);

contentPane.setBorder(new EmptyBorder(5, 14, 5, 5));

setContentPane(contentPane);

contentPane.setLayout(null);

JLabel lblNewLabel = new JLabel("购物系统");

lblNewLabel.setForeground(Color.BLUE);

lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 25));

lblNewLabel.setBounds(165, 10, 100, 55);

contentPane.add(lblNewLabel);

JButton btnNewButton = new JButton("购买商品");

btnNewButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

Frame1 d = new Frame1();

d.setVisible(true);

dispose();

}

});

btnNewButton.addMouseListener(new MouseAdapter() {

GetGoods s = new GetGoods();

Menu m = new Menu();

@Override

public void mouseClicked(MouseEvent e) {

m.Menu();

}

});

btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 16));

btnNewButton.setForeground(Color.BLUE);

btnNewButton.setBounds(128, 64, 165, 36);

contentPane.add(btnNewButton);

JButton button = new JButton("查看购物车");

button.addMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent e) {

CarFrame d = new CarFrame();

d.setVisible(true);

dispose();

}

});

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

}

});

button.setForeground(Color.BLUE);

button.setFont(new Font("微软雅黑", Font.PLAIN, 16));

button.setBounds(128, 108, 165, 36);

contentPane.add(button);

JButton button_3 = new JButton("商家系统");

button_3.addMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent e) {

BussinessFrame d = new BussinessFrame();

d.setVisible(true);

dispose();

}

});

button_3.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

}

});

button_3.setForeground(Color.BLUE);

button_3.setFont(new Font("微软雅黑", Font.PLAIN, 16));

button_3.setBounds(128, 154, 165, 36);

contentPane.add(button_3);

JButton button_4 = new JButton("结账");

button_4.addMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent e) {

dispose();

}

});

button_4.setForeground(Color.BLUE);

button_4.setFont(new Font("微软雅黑", Font.PLAIN, 16));

button_4.setBounds(128, 212, 165, 36);

contentPane.add(button_4);

}

}

package Main;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import javax.swing.text.BadLocationException;

import com.mysql.jdbc.Statement;

import javax.swing.JLabel;

import java.awt.Color;

import java.awt.Font;

import java.awt.List;

import javax.swing.JTextField;

import javax.swing.JButton;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.io.IOException;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.Scanner;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import javax.swing.JTextArea;

public class Frame1 extends JFrame {

private JPanel contentPane;

private JTextField textField;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

Frame1 frame = new Frame1();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the frame.

*/

public Frame1() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 461);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

contentPane.setLayout(null);

JLabel lblNewLabel = new JLabel("请输入您要购买的商品id:");

lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 22));

lblNewLabel.setForeground(Color.BLUE);

lblNewLabel.setBounds(10, 280, 273, 59);

contentPane.add(lblNewLabel);

JTextField textField_1 = new JTextField();

String value = textField_1.getText().trim();

textField = new JTextField();

Menu m = new Menu();

textField.setBounds(10, 10, 414, 59);

contentPane.add(textField);

textField.setColumns(10);

System.out.println(value);

textField_1.setBounds(278, 295, 73, 38);

contentPane.add(textField_1);

textField_1.setColumns(10);

JButton btnNewButton = new JButton("购买");

AddCarGoods g = new AddCarGoods();

btnNewButton.addMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent e) {

g.Addcargoods(Integer.parseInt(textField_1.getText().trim()));

}

});

btnNewButton.setBounds(359, 274, 65, 59);

contentPane.add(btnNewButton);

JTextArea textArea = new JTextArea();

textArea.setBounds(10, 79, 414, 156);

contentPane.add(textArea);

JButton btnNewButton_1 = new JButton("查询可购买商品");

btnNewButton_1.addMouseListener(new MouseAdapter() {

String url = "jdbc:mysql://localhost:3306/goods";

String userName = "root";

String password = "kamisama";

String driverName = "com.mysql.jdbc.Driver";

String strSql = "select * from good";

Scanner sc = new Scanner(System.in);

Connection con = null;

Statement pstmt = null;

ResultSet rs = null;

String driverName1 = "com.mysql.jdbc.Driver";

@Override

public void mouseClicked(MouseEvent e) {

try {

Class.forName(driverName);

con = (Connection) DriverManager.getConnection(url, userName, password);

pstmt = (Statement) con.createStatement();

rs = pstmt.executeQuery(strSql);

while (rs.next()) {

int id = rs.getInt("id");

String name = rs.getString("name");

Double price = rs.getDouble("price");

int num = rs.getInt("num");

String description = rs.getString("description");

System.out.print("id=" + id + " name="+name+ " price="+price+" num=" + num+" description="+description+"\n");

String str = "id=" + id + " name="+name+ " price="+price+" num=" + num+" description="+description+"\n";

textArea.append(str);

}

} catch (ClassNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}catch (SQLException e1){

e1.printStackTrace();

}finally {

if (rs != null)

try {

rs.close();

} catch (Exception e1) {

e1.printStackTrace();

}

if (pstmt != null){

try {

pstmt.close();// 关闭语句

} catch (Exception e1) {

e1.printStackTrace();

}

}

if (con != null) {

try {

con.close();// 关闭连接

} catch (Exception e1) {

e1.printStackTrace();

}

}

}

}

});

btnNewButton_1.setBounds(20, 342, 279, 49);

contentPane.add(btnNewButton_1);

JButton btnNewButton_2 = new JButton("返回");

btnNewButton_2.addMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent e) {

Fframe f = new Fframe();

f.setVisible(true);

dispose();

}

});

btnNewButton_2.setBounds(309, 343, 93, 48);

contentPane.add(btnNewButton_2);

}

}

package Main;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import com.mysql.jdbc.Statement;

import javax.swing.JTextField;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.Scanner;

import java.awt.event.ActionEvent;

import javax.swing.JLabel;

import java.awt.Color;

import java.awt.Font;

import javax.swing.JTextArea;

public class CarFrame extends JFrame {

private JPanel contentPane;

private JTextField textField;

private JTextField textField_1;

private JTextField textField_2;

private JTextField textField_3;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

CarFrame frame = new CarFrame();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the frame.

*/

public CarFrame() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 420);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

contentPane.setLayout(null);

textField = new JTextField();

textField.setBounds(33, 10, 369, 32);

contentPane.add(textField);

textField.setColumns(10);

JTextArea textArea = new JTextArea();

textArea.setBounds(10, 58, 424, 110);

contentPane.add(textArea);

JButton btnNewButton = new JButton("查看购物车商品");

btnNewButton.addMouseListener(new MouseAdapter() {

String url = "jdbc:mysql://localhost:3306/goods";

String userName = "root";

String password = "kamisama";

String driverName = "com.mysql.jdbc.Driver";

String strSql = "select * from cars";

Scanner sc = new Scanner(System.in);

Connection con = null;

Statement pstmt = null;

ResultSet rs = null;

String driverName1 = "com.mysql.jdbc.Driver";

@Override

public void mouseClicked(MouseEvent e) {

try {

Class.forName(driverName);

con = (Connection) DriverManager.getConnection(url, userName, password);

pstmt = (Statement) con.createStatement();

rs = pstmt.executeQuery(strSql);

while (rs.next()) {

int id = rs.getInt("id");

String name = rs.getString("name");

Double price = rs.getDouble("price");

int num = rs.getInt("num");

String description = rs.getString("description");

double sum = rs.getDouble("sum");

System.out.print("id=" + id + " name="+name+ " price="+price+" num=" + num+" description="+description+" sum="+sum+"\n");

String str = "id=" + id + " name="+name+ " price="+price+" num=" + num+" description="+description+" sum="+sum+"\n";

textArea.append(str);

}

} catch (ClassNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}catch (SQLException e1){

e1.printStackTrace();

}finally {

if (rs != null)

try {

rs.close();

} catch (Exception e1) {

e1.printStackTrace();

}

if (pstmt != null){

try {

pstmt.close();// 关闭语句

} catch (Exception e1) {

e1.printStackTrace();

}

}

if (con != null) {

try {

con.close();// 关闭连接

} catch (Exception e1) {

e1.printStackTrace();

}

}

}

}

});

btnNewButton.setBounds(10, 178, 170, 32);

contentPane.add(btnNewButton);

JButton btnNewButton_1 = new JButton("返回");

btnNewButton_1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

Fframe f = new Fframe();

f.setVisible(true);

dispose();

}

});

btnNewButton_1.setBounds(227, 178, 170, 32);

contentPane.add(btnNewButton_1);

JLabel lblNewLabel = new JLabel("请输入您要删除的购物车商品id");

lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 14));

lblNewLabel.setForeground(Color.BLUE);

lblNewLabel.setBounds(20, 220, 214, 31);

contentPane.add(lblNewLabel);

textField_1 = new JTextField();

JTextField textField_1 = new JTextField();

String value = textField_1.getText().trim();

textField_1.setBounds(237, 220, 85, 31);

contentPane.add(textField_1);

textField_1.setColumns(10);

JButton btnNewButton_2 = new JButton("确认删除");

DeleteCarGoods d = new DeleteCarGoods();

btnNewButton_2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

d.DeleteCargoods(Integer.parseInt(textField_1.getText().trim()));

}

});

btnNewButton_2.setBounds(331, 221, 93, 31);

contentPane.add(btnNewButton_2);

JLabel lblid = new JLabel("请输入您要修改数量的购物车商品id");

lblid.setForeground(Color.BLUE);

lblid.setFont(new Font("微软雅黑", Font.PLAIN, 14));

lblid.setBounds(10, 285, 233, 31);

contentPane.add(lblid);

textField_2 = new JTextField();

textField_2.setColumns(10);

textField_2.setBounds(237, 286, 85, 31);

contentPane.add(textField_2);

JLabel label = new JLabel("请输入您要修改数量的购物车商品数量");

label.setForeground(Color.BLUE);

label.setFont(new Font("微软雅黑", Font.PLAIN, 14));

label.setBounds(10, 340, 244, 31);

contentPane.add(label);

textField_3 = new JTextField();

textField_3.setColumns(10);

textField_3.setBounds(251, 346, 85, 31);

contentPane.add(textField_3);

UpdataNum u = new UpdataNum();

JButton button_1 = new JButton("确认");

button_1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

String value1 = textField_2.getText().trim();

String value2 = textField_3.getText().trim();

u.updata(Integer.parseInt(value1), Integer.parseInt(value2));

}

});

button_1.setBounds(341, 345, 93, 31);

contentPane.add(button_1);

}

}

package Main;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import javax.swing.JButton;

import java.awt.Color;

import java.awt.Font;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class BussinessFrame extends JFrame {

private JPanel contentPane;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

BussinessFrame frame = new BussinessFrame();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the frame.

*/

public BussinessFrame() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 300);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

contentPane.setLayout(null);

JButton btnNewButton = new JButton("上架商品");

btnNewButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

SellFrame f = new SellFrame();

f.setVisible(true);

dispose();

}

});

btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 24));

btnNewButton.setForeground(Color.BLUE);

btnNewButton.setBounds(70, 62, 299, 52);

contentPane.add(btnNewButton);

JButton button = new JButton("下架商品");

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

DownGoodsFrame f = new DownGoodsFrame();

f.setVisible(true);

dispose();

}

});

button.setFont(new Font("微软雅黑", Font.PLAIN, 24));

button.setForeground(Color.BLUE);

button.setBounds(70, 124, 299, 60);

contentPane.add(button);

JButton btnNewButton_1 = new JButton("返回");

btnNewButton_1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

Fframe f = new Fframe();

f.setVisible(true);

dispose();

}

});

btnNewButton_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));

btnNewButton_1.setForeground(Color.BLUE);

btnNewButton_1.setBounds(309, 194, 103, 43);

contentPane.add(btnNewButton_1);

}

}

package Main;

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import javax.swing.JLabel;

import java.awt.Color;

import java.awt.Font;

import javax.swing.JTextField;

import javax.swing.JButton;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class SellFrame extends JFrame {

private JPanel contentPane;

private JTextField textField;

private JTextField textField_1;

private JTextField textField_2;

private JTextField textField_3;

/**

* Launch the application.

*/

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

SellFrame frame = new SellFrame();

frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

/**

* Create the frame.

*/

public SellFrame() {

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 450, 300);

contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

contentPane.setLayout(null);

JLabel lblNewLabel = new JLabel("请输入您的商品名称");

lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 24));

lblNewLabel.setForeground(Color.BLUE);

lblNewLabel.setBounds(22, 31, 224, 36);

contentPane.add(lblNewLabel);

JLabel label = new JLabel("请输入您的商品单价");

label.setForeground(Color.BLUE);

label.setFont(new Font("微软雅黑", Font.PLAIN, 24));

label.setBounds(22, 73, 224, 36);

contentPane.add(label);

JLabel label_1 = new JLabel("请输入您的商品数量");

label_1.setForeground(Color.BLUE);

label_1.setFont(new Font("微软雅黑", Font.PLAIN, 24));

label_1.setBounds(22, 116, 224, 36);

contentPane.add(label_1);

JLabel label_2 = new JLabel("请输入您的商品描述");

label_2.setForeground(Color.BLUE);

label_2.setFont(new Font("微软雅黑", Font.PLAIN, 24));

label_2.setBounds(22, 162, 224, 36);

contentPane.add(label_2);

textField = new JTextField();

textField.setBounds(267, 31, 157, 34);

contentPane.add(textField);

textField.setColumns(10);

textField_1 = new JTextField();

textField_1.setColumns(10);

textField_1.setBounds(267, 73, 157, 34);

contentPane.add(textField_1);

textField_2 = new JTextField();

textField_2.setColumns(10);

textField_2.setBounds(267, 116, 157, 34);

contentPane.add(textField_2);

textField_3 = new JTextField();

textField_3.setColumns(10);

textField_3.setBounds(267, 162, 157, 34);

contentPane.add(textField_3);

JButton btnNewButton = new JButton("返回");

btnNewButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

Fframe f = new Fframe();

f.setVisible(true);

dispose();

}

});

btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 24));

btnNewButton.setForeground(Color.BLUE);

btnNewButton.setBounds(293, 206, 117, 45);

contentPane.add(btnNewButton);

JButton button = new JButton("确认");

button.addMouseListener(new MouseAdapter() {

GoodsSQL s = new GoodsSQL();

@Override

public void mouseClicked(MouseEvent e) {

String value1 = textField.getText().trim();

String value2 = textField_1.getText().trim();

String value3 = textField_2.getText().trim();

String value4 = textField_3.getText().trim();

s.Sell(value1, Double.parseDouble(value2), Integer.parseInt(value3), value4);

}

});

button.setForeground(Color.BLUE);

button.setFont(new Font("微软雅黑", Font.PLAIN, 24));

button.setBounds(22, 206, 117, 45);

contentPane.add(button);

}

}

package Main;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.Scanner;

public class AddCarGoods {

String url = "jdbc:mysql://localhost:3306/goods";

String userName = "root";

String password = "kamisama";

String driverName = "com.mysql.jdbc.Driver";

String strSql1 = "insert into cars(name,price,num,description) select name,price,num,description from good where id = ?";

String strSql2 = "updates cars et sum=numprice where id = ?";

Connection con1 = null;

java.sql.PreparedStatement pstmt1 = null;

java.sql.PreparedStatement pstmt2 = null;

ResultSet rs = null;

String driverName1 = "com.mysql.jdbc.Driver";

Scanner sc = new Scanner(System.in);

public void Addcargoods(int i){

try {

Class.forName(driverName);// jdbc4.0 后无需使用这句进行驱动注册操作

con1 =DriverManager.getConnection(url, userName, password); // 根据参数的插入数据

pstmt1 = con1.prepareStatement(strSql1);

pstmt1.setInt(1, i);

pstmt2 = con1.prepareStatement(strSql2);

pstmt2.setInt(1, i);

pstmt1.executeUpdate();

pstmt2.executeUpdate();

} catch (SQLException e) {

e.printStackTrace();

} catch (ClassNotFoundException e) {

e.printStackTrace();

} finally {/下面资源释放,可以使用try..with..resources语法简化*/

if (rs != null) {

try {

rs.close();

rs.close();

} catch (SQLException e) {

e.printStackTrace();

}

}

if (pstmt1 != null) {

try {

pstmt1.close();

pstmt1 = null;

} catch (SQLException e) {

e.printStackTrace();

}

}

if (con1 != null)

try {

con1.close();

con1 = null;

} catch (SQLException e) {

e.printStackTrace();

}

}

}

}

package Main;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.Scanner;

import com.mysql.jdbc.PreparedStatement;

public class GoodsSQL{

String url = "jdbc:mysql://localhost:3306/goods";

String userName = "root";

String password = "kamisama";

String driverName = "com.mysql.jdbc.Driver";

String strSql = "insert into good(name,price,num,description) values(?,?,?,?)";

Scanner sc = new Scanner(System.in);

Connection con = null;

PreparedStatement pstmt = null;

ResultSet rs = null;

String driverName1 = "com.mysql.jdbc.Driver";

public void Sell(String name,double price,int num,String description){ //上架商品

try {

Class.forName(driverName1);// 加载MySql的驱动程序

con = (Connection) DriverManager.getConnection(url, userName, password); // 根据参数的插入数据

pstmt = (PreparedStatement) con.prepareStatement(strSql);

pstmt.setString(1, name);

pstmt.setDouble(2,price);

pstmt.setInt(3, num);

pstmt.setString(4, description);

pstmt.executeUpdate();

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e){

e.printStackTrace();

}finally {

if (rs != null)

try {

rs.close();

} catch (Exception e) {

e.printStackTrace();

}

if (pstmt != null){

try {

pstmt.close();// 关闭语句*/

} catch (Exception e) {

e.printStackTrace();

}

}

if (con != null) {

try {

con.close();// 关闭连接

} catch (Exception e) {

e.printStackTrace();

}

}

}

}

}

package Main;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.Scanner;

public class DeleteGoods{

String url = "jdbc:mysql://localhost:3306/goods";

String userName = "root";

String password = "kamisama";

String driverName = "com.mysql.jdbc.Driver";

String strSql = "delete from good where id = ?";

Scanner sc = new Scanner(System.in);

Connection con1 = null;

java.sql.PreparedStatement pstmt1 = null;

ResultSet rs1 = null;

String driverName2 = "com.mysql.jdbc.Driver";

public void delete(int i){

try {

Class.forName(driverName2);// 加载MySql的驱动程序

con1 = (Connection) DriverManager.getConnection(url, userName, password); // 根据参数的插入数据

pstmt1 = con1.prepareStatement(strSql);

pstmt1.setInt(1, i);

pstmt1.executeUpdate();

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e){

e.printStackTrace();

}finally {

if (rs1 != null)

try {

rs1.close();

} catch (Exception e) {

e.printStackTrace();

}

if (pstmt1 != null){

try {

pstmt1.close();// 关闭语句*/

} catch (Exception e) {

e.printStackTrace();

}

}

if (con1 != null) {

try {

con1.close();// 关闭连接

} catch (Exception e) {

e.printStackTrace();

}

}

}

}

}

Java购物车swing_JAVA课程设计--购物车相关推荐

  1. java购物车设计_Java面向对象课程设计——购物车

    Java面向对象课程设计--购物车 小组成员:余景胜.刘格铭.陈国雄.达瓦次仁 一.前期调查 流程 客人(Buyer)先在商城(Mall)中浏览商品(Commidity),将浏览的商品加入购物车(Sh ...

  2. JAVA高级应用课程设计(网上书城系统——会员登陆模块的设计与实现)

    课程设计报告 课   程  名   称: JAVA高级应用课程设计 设   计  题   目:网上书城系统--会员登陆模块的设计与实现 目 录 一.开发背景. 1 (一)背景概述. 1 (二)发展前景 ...

  3. java课设推荐,《Java程序设计》课程设计报告推荐.docx

    <Java程序设计>课程设计报告推荐 <Java程序设计>课程设计报告2015-2016学年 第一学期设计题目整数进制转换学生姓名邹晓刚学 号0专业班级信管1303指导教师 姜 ...

  4. 大一java图书馆管理系统课程设计

    大一java图书馆管理系统课程设计 代码仅供参考!!!仅供参考!!! 效果图如下 管理员用户名:123  密码123 密码错误的话进入项目resources文件夹有个LMS数据库,使用数据库客户端打开 ...

  5. java打字训练课程设计_Java打字训练课程设计

    Java打字训练课程设计 软 件 学 院课程设计报告书课程名称 设计题目 专业班级 学 号 姓 名 指导教师 年 月目录1 设计时间 12 设计目的 13 设计任务 14 设计内容 14.1 需求分析 ...

  6. 记忆测试系统java代码_JAVA课程设计——记忆测试系统(附源程序).doc

    <JAVA程序设计>课程设计报告 题 目: 记忆游戏 姓 名: 学 号: 班 级: 指导教师: 完成时间 成 绩: 信息工程学院 2015年6月 目 录 TOC \o "1-5& ...

  7. Java拼图游戏总结,Java拼图游戏课程设计报告

    Java拼图游戏课程设计报告 JavaJava 程序设计与应用开发 课程设计报告程序设计与应用开发 课程设计报告 设计题目 拼图大作战 学生姓名 学生班级 学生学号 指导教师 完成时间2016 年 0 ...

  8. java贪吃蛇课程设计报告_java贪吃蛇课程设计报告().doc

    java贪吃蛇课程设计报告() <Java应用开发> 课程设计报告 题 目: JAVA小游戏 - 贪吃蛇 指导老师: 姓 名: 专 业: 班 级: 日 期: 目 录 一.系统总体设计1 ( ...

  9. java课程设计日历记事本_《Java程序设计》课程设计日历记事本.doc

    <Java程序设计>课程设计日历记事本 PAGE PAGE 2 本科生课程设计 课程名称 Java程序设计课程设计 课程编号 j1620011 题目 日历记事本 学号 2008116222 ...

最新文章

  1. PTA 基础编程题目集 7-27 冒泡法排序 C语言
  2. 8个方法解决90%的NLP问题
  3. Extjs4.2——Panel
  4. unbutu安装搜狗输入法【转载】
  5. 【java学习之路】数据库连接JDBC
  6. 【我的电赛日记(二)】ADF4351锁相环模块
  7. Android UI美化——颜色
  8. 计算机软件工程专业选科要求,选考科目科普:软件工程专业要求哪些选考科目?...
  9. 图解通信原理与案例分析-14:“大哥大”与1G模拟蜂窝移动通信案例--频率调制与频分多址FDMA
  10. Mac电脑动态壁纸怎么设置
  11. 电脑声卡维修经验和实例完全分析
  12. Python非线性拟合笔记
  13. 2020 数据科学平台领域最具商业合作价值企业盘点
  14. 墨翟科技(上海)有限公司
  15. 【FFmpeg编码实战】(2)将YUV420P图片集编码成H.264视频文件(方法二)
  16. 坑逼的PL2303与WIN11
  17. 物联网开发板设计笔记 (1/7)__ 设计思路
  18. 如何快速备份linux文件夹?【高效】
  19. 计算机应用基础试题库,2017年计算机应用基础模拟试题「题库」
  20. CSDN校园活动社开展“开学季活动”

热门文章

  1. ospf工作原理_OSPF动态路由配置经典案例
  2. 光纤收发器常见故障及解决方法
  3. 【渝粤教育】电大中专消费者行为学30分钟交卷作业 题库
  4. 【渝粤题库】国家开放大学2021春3979会计学概论题目
  5. 【渝粤题库】国家开放大学2021春1332中文学科论文写作题目
  6. SX1268与SX1278、SX1276对比分析以及选型南
  7. matlab查找替换指令,使用matlab GUI在.txt文件中编辑特定数字使用搜索/替换
  8. mysql的sql执行原理图_性能测试MySQL之SQL运行原理
  9. having和where可以同时使用吗_阴、阳离子聚丙烯酰胺可以同时混合溶解使用吗?...
  10. java布尔多少字节,在Java中将字节转换为长度为4的布尔数组