?? orderentity.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 + -