⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orderentity.java

📁 使用JSP技术实现销售管理平台
💻 JAVA
字号:
package cart;
import java.sql.*;
import java.util.*;
import java.math.*;

public class OrderEntity
{
	private String id;
	private String userName;
	private String orderDate;
	private String orderPrice;
	
	
	String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
	String sConnStr = "jdbc:odbc:cart";
	Connection conn = null;
	ResultSet rs = null;	
	
	
	public OrderEntity(String id,String userName,String orderDate,String orderPrice)
	{
		try 
		{
			Class.forName(sDBDriver); 
	    	}
	  	catch(java.lang.ClassNotFoundException e) 
	  	{
			System.err.println("OrderItemEntity: " + e.getMessage());
		}
		
		this.id=id;
		this.userName=userName;
		this.orderDate=orderDate;
		this.orderPrice=orderPrice;
	}
	
	public String insertOrder() throws SQLException
	{
		//insert into database
		String sql="insert into orderlist(user_name,order_date,order_price) values(?,?,?) ";
	
		
		rs = null;
		try 
		{
			conn = DriverManager.getConnection(sConnStr); 
			PreparedStatement prepStmt = conn.prepareStatement(sql);
			
			String curDate=(java.util.Calendar.getInstance().getTime()).toString();
			
			prepStmt.setString(1,userName);
			prepStmt.setString(2,curDate);
			prepStmt.setString(3,orderPrice);
			
			
			prepStmt.executeUpdate();
		} 
		catch(SQLException ex) 
		{ 
			System.err.println("OrderEntity executeQuery: " + ex.getMessage());
		}
		
		//get the id
          	String selectStatement ="select id " +"from orderlist where user_name=?  order by id desc ";
          	PreparedStatement prepStmt = conn.prepareStatement(selectStatement);
          
          	prepStmt.setString(1,userName);

          	ResultSet rs = prepStmt.executeQuery();
          
	        rs.next();
          	
          	String result=rs.getString(1);
          	
          	return result;
          
		
	}
	
}

⌨️ 快捷键说明

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