java商店购物管理系统_java操纵数据库-商店购物管理系统

这篇博客展示了如何使用Java进行商店购物管理系统的数据库操作,包括获取顾客交易记录和指定顾客交易记录,并且处理可能的SQLException异常。通过JDBC-ODBC桥驱动程序连接到数据库,执行SQL查询来实现数据的检索和删除。
摘要由CSDN通过智能技术生成

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

System.out.println("SQLState:  " + ex.getSQLState());

System.out.println("ErrorCode: " + ex.getErrorCode());

ex = ex.getNextException();

}

}

catch(Exception ex )

{

ex.printStackTrace();

}

}

public ResultSet getDealInfo()                       //获取顾客交易记录的结果集

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");   //指定与数据库连接使用JDBC-ODBC桥驱动程序

String url = "jdbc:odbc:shop";                   //指定数据源名

connection = DriverManager.getConnection(url);   //与数据源建立连接

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";    //创建获取顾客交易记录的SQL语句

statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);  //创建Statement接口实例

rs = statement.executeQuery(sql);                //将数据存入结果集中

}

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)    //获取指定顾客的交易记录的结果集

{

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");   //指定与数据库连接使用JDBC-ODBC桥驱动程序

String url = "jdbc:odbc:shop";                   //指定数据源名

connection = DriverManager.getConnection(url);   //与数据源建立连接

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 + "'";    //创建获取指定顾客交易记录的SQL语句

statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);  //创建Statement接口实例

rs = statement.executeQuery(sql);                //将数据存入结果集中

}

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)    //删除指定顾客的交易记录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值