📄 buyercar.java.bak
字号:
package ebs;
import java.sql.*;
public class Buyercar{
private String bookid=null; //图书编号
private String bookname=null; //书名
private String bookauthor=null; //作者
private String bookpublisher=null; //出版社
private String bookintroduce=null; //简介
private String bookisbn=null; //图书出版号
private String bookprice=null; //价格
private static String strDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
private static String strDBUrl="jdbc:odbc:ebookstore";
java.sql.Connection conn;
java.sql.Statement stmt;
java.sql.ResultSet Rst;
public Buyercar(){
//加载驱动
try{
Class.forName(strDBDriver);
}
catch(java.lang.ClassNotFoundException e){
System.err.println("Buyercar():"+e.getMessage());
}
}
//取当前数据库中全部图书信息
public ResultSet getBookList(){
String strSql=null;
try{
//建立与数据库的连接
conn=DriverManager.getConnection(strDBUrl);
stmt=conn.createStatement();
strSql="select book_id,book_name,book_author,book_publisher,book_introduce,book_isbn,book_price from book_info";
Rst=stmt.executeQuery(strSql);
}
//捕获异常
catch(SQLException e){
System.err.println("Buyercar.getBookList();"+e.getMessage());
}
return Rst;
}
//根据图书的编号给图书的其他信息赋值
private void getBookInfo(String BID){
String strSql=null;
bookname=null;
bookauthor=null; //作者
bookpublisher=null; //出版社
bookintroduce=null; //简介
bookisbn=null; //图书出版号
bookprice=null;
try{
//建立和数据库的连接
conn=DriverManager.getConnection(strDBUrl);
stmt=conn.createStatement();
strSql="Select * from book_info where book_id='"+BID+"'";
Rst=stmt.executeQuery(strSql);
while(Rst.next()){
bookname=Rst.getString("book_name");
bookauthor=Rst.getString("book_author");
bookpublisher=Rst.getString("book_publisher");
bookintroduce=Rst.getString("book_introduce");
bookisbn=Rst.getString("book_isbn");
bookprice=Rst.getString("book_price");
}
}
//捕获异常
catch(SQLException e){
System.err.println("Buyercar.getBookInfo():"+e.getMessage());
}
}
//给图书的编号赋值,同时调用函数给图书的其他信息赋值
public void setBookid(String BID){
this.bookid=BID;
getBookInfo(bookid);
}
//取图书编号
public String getBookid(){
return bookid;
}
public String getBookname(){
return bookname;
}
public String getBookauthor(){
return bookauthor;
}
public String getBookpublisher(){
return bookpublisher;
}
public String getBookintroduce(){
return bookintroduce;
}
public String getBookisbn(){
return bookisbn;
}
public String getBookprice(){
return bookprice;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -