📄 addbooks.java~12~
字号:
package bookmanage;
import javax.swing.*;
import java.io.*;
import java.sql.*;
import jxl.*;
/**
* <p>Title: 图书管理系统</p>
*
* <p>Description: 此类是用来批量增加图书</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: 浙江工业大学信息学院计算机系</p>
*
* @author 曾文秋
* @version 1.0
*/
public class AddBooks {
File fOpen=null;
DBManager db=new DBManager();
ResultSet rs;
public AddBooks(){
JFileChooser fileSelection=new JFileChooser();
File dir=new File("./");
fileSelection.setApproveButtonText("确定");
fileSelection.setCurrentDirectory(dir);
fileSelection.addChoosableFileFilter(new Filter("xls"));
int index=fileSelection.showOpenDialog(null);
if(index==fileSelection.CANCEL_OPTION)
return;
fOpen=fileSelection.getSelectedFile();
String strSql="";
//String yinghao = "\"";
//String maohao="\\";
/*strSql="select * from OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source="+
yinghao+fOpen.getAbsolutePath()+yinghao+";Extended Properties="+yinghao+
"Excel 5.0"+yinghao+";Persist Security Info=False')...student";
System.out.println(strSql);*/
jxl.Workbook rwb=null;
try{
InputStream is=new FileInputStream(fOpen);
rwb = Workbook.getWorkbook(is);
Sheet r = rwb.getSheet(0);
int rows=r.getRows();
int columns=r.getColumns();
String s[]=new String[columns];
for(int i=1;i<rows;i++){
for(int j=0;j<columns;j++){
Cell c=r.getCell(j,i);
s[j]=c.getContents();
}
strSql="exec Pro_InsertBook '"+s[0]+"','"+s[1]+"','"+s[2]+"',"+
""+Float.parseFloat(s[3])+",'"+s[4]+"','"+s[5]+"','"+s[6]+"','"+s[7]+"',"+Integer.parseInt(s[8])+"";
System.out.print(strSql);
//db.executeSql(strSql);
}
}catch(Exception ee){
ee.printStackTrace();
}
//Cell c00 = r.getCell(1, 0);
//String strc00 = c00.getContents();
//System.out.print(strc00);
/*rs=db.getResult(strSql);
boolean isexist=false;
try{
isexist=rs.first();
}catch(SQLException e1){}
if(!isexist)
{
JOptionPane.showMessageDialog(null,"该表没有要倒入的内容 ");
return;
}
else{
try{
rs.beforeFirst();
while(rs.next()){
String strName,strIsbn,strAuthor,strPublisher,strPubDate,strGuanjianzi,strAdress;
float fPrice;
int num;
strName=rs.getString(1);
strIsbn=rs.getString(2);
strAuthor=rs.getString(3);
fPrice=Float.parseFloat(rs.getString(4));
strPublisher=rs.getString(5);
strPubDate=rs.getString(6);
strGuanjianzi=rs.getString(7);
strAdress=rs.getString(8);
num=Integer.parseInt(rs.getString(9));
strSql="exec Pro_InsertBook '"+strName+"','"+strIsbn+"','"+strAuthor+"',"+
""+fPrice+",'"+strPublisher+"','"+strPubDate+"','"+strGuanjianzi+"','"+strAdress+"',"+num+"";
db.executeSql(strSql);
}
}catch(SQLException e){
e.printStackTrace();
}
}
db.close();*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -