该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
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) //删除指定顾客的交易记录