?? orderbean.java
字號:
package wdm;
import java.sql.*;
public class OrderBean {
private static String strDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
private static String strDBUrl = "jdbc:odbc:bookstore";
private Connection conn = null;
private ResultSet rs = null;
private String bookinfo = null;
private String oderprice = null;
private String orderDate = null;
private int orderID = 0;
private String orderRem = null;
private String receiverAddress = null;
private String receiverName = null;
private String receiverZip = null;
private String userID = null;
public OrderBean() {
try {
Class.forName(strDBDriver);
} catch (java.lang.ClassNotFoundException e) {
System.err.println("OrderBean ():" + e.getMessage());
}
}
public static void main(String args[]) {
}
/**
* 返回定單的總價。
*
* @return String
*/
public String getOrderPrice() {
return oderprice;
}
/**
* 返回定單的日期 。
*
* @return String
*/
public String getOrderDate() {
orderDate = new java.util.Date().toString();
return orderDate;
}
/**
* 返回定單的ID號。
*
* @return String
*/
public int getOrderID() {
return orderID;
}
/**
* 返回定單的備注信息。
*
* @return String
*/
public String getOrderRem() {
return orderRem;
}
/**
* 返回接收者的地址
*
* @return String
*/
public String getReceiverAddress() {
return receiverAddress;
}
/**
* 返回接收者的姓名。
*
* @return String
*/
public String getReceiverName() {
return receiverName;
}
/**
* 返回接收者的郵政編碼。
*
* @return String
*/
public String getReceiverZip() {
return receiverZip;
}
/**
* 獲得用戶ID。
*
* @return String
*/
public String getUserID() {
return userID;
}
/**
* 給圖書信息賦值。
*
* @param newBooks
* Java.util.Properties
*/
public void setBookinfo(String newBookinfo) {
bookinfo = newBookinfo;
createNewOrder();
int fromIndex = 0;
int tmpIndex = 0;
int tmpEnd = 0;
String strSql = null;
try {
conn = DriverManager.getConnection(strDBUrl);
Statement stmt = conn.createStatement();
while (bookinfo.indexOf(';', fromIndex) != -1) {
tmpEnd = bookinfo.indexOf(';', fromIndex);
tmpIndex = bookinfo.lastIndexOf('=', tmpEnd);
strSql = "insert into orderdetail(orderID ,bookISBN ,bookcount) values("
+ getOrderID()
+ ", '"
+ bookinfo.substring(fromIndex, tmpIndex)
+ "', '"
+ bookinfo.substring(tmpIndex + 1, tmpEnd) + "')";
stmt.executeUpdate(strSql);
fromIndex = tmpEnd + 1;
}
stmt.close();
conn.close();
} catch (SQLException e) {
System.err.println("OrderBean.setBookinfo():" + e.getMessage());
}
}
/**
* 給定單的總價賦值。
*
* @param newOderprice
* String
*/
public void setOderprice(String newOderprice) {
oderprice = newOderprice;
}
/**
* 給定單的備注賦值。
*
* @param newOrderRem
* String
*/
public void setOrderRem(String newOrderRem) {
orderRem = newOrderRem;
}
/**
* 給接收者的地址賦值。
*
* @param newReceiverAddress
* String
*/
public void setReceiverAddress(String newReceiverAddress) {
receiverAddress = newReceiverAddress;
}
/**
* 給接收者的姓名賦值。
*
* @param newReceiverName
* String
*/
public void setReceiverName(String newReceiverName) {
receiverName = newReceiverName;
}
/**
* 給接收者的郵政編碼代碼賦值。
*
* @param newReceiverZip
* String
*/
public void setReceiverZip(String newReceiverZip) {
receiverZip = newReceiverZip;
}
/**
* 給用戶代碼賦值。
*
* @param newUserID
* String
*/
public void setUserID(String newUserID) {
userID = newUserID;
}
/**
* 創建一個新定單
*/
private void createNewOrder() {
String strSql = null;
try {
conn = DriverManager.getConnection(strDBUrl);
Statement stmt = conn.createStatement();
strSql = "insert into orderInfo (userID,receiverName,receiverAddress,receiverZip,orderRem,orderPrice,Orderdate)"
+ " values( '"
+ getUserID()
+ "', '"
+ getReceiverName()
+ "', '"
+ getReceiverAddress()
+ "', '"
+ getReceiverZip()
+ "', '"
+ getOrderRem()
+ "', '"
+ getOrderPrice()
+ "','"
+ getOrderDate() + "')";
stmt.executeUpdate(strSql);
strSql = "select orderID from orderInfo where userID = '"
+ getUserID() + "' and receiverName ='" + getReceiverName()
+ "' and receiverAddress ='" + getReceiverAddress()
+ "' and receiverZip ='" + getReceiverZip()
+ "' and orderRem ='" + getOrderRem()
+ "' and orderPrice ='" + getOrderPrice()
+ "' and Orderdate ='" + getOrderDate()
+ "' and orderID=(select max(orderID) from orderInfo)";
orderID = orderID + 1;
rs = stmt.executeQuery(strSql);
while (rs.next()) {
orderID = rs.getInt("orderID");
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
System.err.println("OrderBean.createNewOrder:" + e.getMessage());
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -