商店购物java程序_java操纵数据库-商店购物管理系统
該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓
System.out.println("SQLState:??"?+?ex.getSQLState());
System.out.println("ErrorCode:?"?+?ex.getErrorCode());
ex?=?ex.getNextException();
}
}
catch(Exception?ex?)
{
ex.printStackTrace();
}
}
public?ResultSet?getDealInfo()???????????????????????//獲取顧客交易記錄的結(jié)果集
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");???//指定與數(shù)據(jù)庫連接使用JDBC-ODBC橋驅(qū)動(dòng)程序
String?url?=?"jdbc:odbc:shop";???????????????????//指定數(shù)據(jù)源名
connection?=?DriverManager.getConnection(url);???//與數(shù)據(jù)源建立連接
String?sql?=?"select?cart_table.product_id,cart_table.buy_number,cart_table.customer_name,cart_table.customer_address";
sql+=",product_table.product_name?from?cart_table,product_table?where?cart_table.product_id=product_table.product_id";????//創(chuàng)建獲取顧客交易記錄的SQL語句
statement?=?connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);??//創(chuàng)建Statement接口實(shí)例
rs?=?statement.executeQuery(sql);????????????????//將數(shù)據(jù)存入結(jié)果集中
}
catch(SQLException?ex)
{
//捕捉異常
System.out.println("\nERROR:-----?SQLException?-----\n");
while?(ex?!=?null)
{
System.out.println("Message:???"?+?ex.getMessage());
System.out.println("SQLState:??"?+?ex.getSQLState());
System.out.println("ErrorCode:?"?+?ex.getErrorCode());
ex?=?ex.getNextException();
}
}
catch(Exception?ex?)
{
ex.printStackTrace();
}
return?rs;
}
public?ResultSet?getSingleDeal(String?customerName)????//獲取指定顧客的交易記錄的結(jié)果集
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");???//指定與數(shù)據(jù)庫連接使用JDBC-ODBC橋驅(qū)動(dòng)程序
String?url?=?"jdbc:odbc:shop";???????????????????//指定數(shù)據(jù)源名
connection?=?DriverManager.getConnection(url);???//與數(shù)據(jù)源建立連接
String?sql?=?"select?cart_table.product_id,cart_table.buy_number,cart_table.customer_name,cart_table.customer_address";
sql+=",product_table.product_name?from?cart_table,product_table?where?cart_table.product_id=product_table.product_id?and?cart_table.customer_name='"?+?customerName?+?"'";????//創(chuàng)建獲取指定顧客交易記錄的SQL語句
statement?=?connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);??//創(chuàng)建Statement接口實(shí)例
rs?=?statement.executeQuery(sql);????????????????//將數(shù)據(jù)存入結(jié)果集中
}
catch(SQLException?ex)
{
//捕捉異常
System.out.println("\nERROR:-----?SQLException?-----\n");
while?(ex?!=?null)
{
System.out.println("Message:???"?+?ex.getMessage());
System.out.println("SQLState:??"?+?ex.getSQLState());
System.out.println("ErrorCode:?"?+?ex.getErrorCode());
ex?=?ex.getNextException();
}
}
catch(Exception?ex?)
{
ex.printStackTrace();
}
return?rs;
}
public?void?delSingleCustomerDeal(String?customerName)????//刪除指定顧客的交易記錄
總結(jié)
以上是生活随笔為你收集整理的商店购物java程序_java操纵数据库-商店购物管理系统的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 拓扑排序_拓扑排序(top
- 下一篇: java publickey_Java中