orderentity.java

来自「一个网上购物车的代码,网上找到的,给大家分享下」· Java 代码 · 共 78 行

JAVA
78
字号
package cart;
import java.sql.*;
import java.math.*;
import java.util.*;
public class OrderEntity
{
	private String id;

	private String username;
	private String orderDate;
	private String orderPrice;
	public static String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
	public static String sConnStr = "jdbc:odbc:cart";
	public static Connection conn = null;
	ResultSet rs=null;
	
	
	public OrderEntity(String id,String username,String orderDate,String orderPrice)
	{
		try
		{
			Class.forName(sDBDriver);
			
		}
		catch(Exception ee)
		{
			System.out.println(ee);
			
		}
		this.id=id;
		this.username=username;
		this.orderDate=orderDate;
		this.orderPrice=orderPrice;
		
		
	}
	public String insertOrderItem() throws SQLException
	{
		String sql="insert into orderlist(user_name,order_date,order_price) values(?,?,?)";
	
			rs=null;
			
	
		try
		{
			conn=DriverManager.getConnection(sConnStr);
			PreparedStatement pre=conn.prepareStatement(sql);
			String time=new java.util.Date().toLocaleString().toString();
			pre.setString(1,this.username);
			pre.setString(2,time);
			pre.setString(3,this.orderPrice);
			
			pre.executeQuery();
			System.out.println("success");
			
	
			
	
			
		}
		catch(Exception ee)
		{
			System.out.println(ee);
			
	
		}
		String selstr="select id from orderlist where user_name=? order by id desc";
		PreparedStatement st=conn.prepareStatement(selstr);
		st.setString(1,this.username);
		ResultSet rs=st.executeQuery();
		rs.next();
		String result=rs.getString(1);
		return result;
		
		
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?