📄 orderentity.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -