JavaWeb.购物车项目

前言:本章纯代码,后期会修改。

一.数据库代码

--用户表
create table shop_user(
     id number primary key,
     account varchar2(30) not null,
     password varchar2(30) not null 
);

insert into shop_user values(1,'xxx','xxx123');

--商品表
create table shop_goods(
     id number primary key,
     name varchar2(30) not null,
     price number default 0.0,--价格
     info varchar2(200) default '三五产品' not null--简介
);

commit

注意一定要commit提交,因为有可能拿不到数据。

二.项目代码

导入美化包,jar包

User.java代码

package com.zking.pojo;

public class User {
          
	private Integer id;
	private String account;
	private String password;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getAccount() {
		return account;
	}
	public void setAccount(String account) {
		this.account = account;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public User(Integer id, String account, String password) {
		super();
		this.id = id;
		this.account = account;
		this.password = password;
	}
	public User() {
		super();
		// TODO Auto-generated constructor stub
	}
	
     
	
}

 Goods.java代码

package com.zking.pojo;

public class Goods {

	private Integer id;
	private String name;
	private Integer price;
	private String info;
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getPrice() {
		return price;
	}
	public void setPrice(Integer price) {
		this.price = price;
	}
	public String getInfo() {
		return info;
	}
	public void setInfo(String info) {
		this.info = info;
	}
	public Goods(Integer id, String name, Integer price, String info) {
		super();
		this.id = id;
		this.name = name;
		this.price = price;
		this.info = info;
	}
	public Goods() {
		super();
		// TODO Auto-generated constructor stub
	}
	@Override
	public String toString() {
		return "Goods [id=" + id + ", name=" + name + ", price=" + price + ", info=" + info + "]";
	}
	

}

DBHelper.java代码

package com.zking.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBHelper {

	//加载驱动
    static{
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    //定义链接字符串
    private static final String URL="jdbc:oracle:thin:@localhost:1521:orcl";

    //获得链接
    public static Connection getCon() {
        try {
            return DriverManager.getConnection(URL,"scott","sa123");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    //关闭资源
    public static void close(Connection con,PreparedStatement ps, ResultSet rs) {
        try {
            if (con!=null&&!con.isClosed()) {
                con.close();
            }if (ps!=
  • 16
    点赞
  • 50
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值