package totabelaction;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaxswingJOptionPane;
import topdfTableToPdf;
import totabelviewTabelData;
import totabelxlsExcelDemo;
public class TableAction implements ActionListener {
TabelData data;
public TableAction(TabelData data) {
thisdata = data;
}
public void actionPerformed(ActionEvent e) {
String str = egetActionCommand();
if ("添加"equals(str)) {
dataaddData();
} else if ("导出到Excel"equals(str)) {
ExcelDemo demo = new ExcelDemo();
demomethod(data);
} else if ("删除"equals(str)) {
if (datagetRow() != -1) {
datadelRow();
} else {
JOptionPaneshowMessageDialog(null, "请选择要删除的行!");
}
}else if("从Excel导入"equals(str)){
datagetXlsInfo();
}else if("从Excel导入到数据库"equals(str)){
datatoDb();
}else if("从table导出到pdf"equals(str)){
TableToPdf pdf=new TableToPdf();
pdfnewPage(data);
}else if("计算学分"equals(str)){
datagetXlsInfoToCredit();
}
}
}
第二个类:数据库连接
package totabeldb;
import javasqlConnection;
import javasqlDriverManager;
import javasqlResultSet;
import javasqlSQLException;
import javasqlStatement;
public class JdbcConnection {
private static JdbcConnection con;
public static JdbcConnection getCon() {
if (con == null) {
con = new JdbcConnection();
}
return con;
}
public Connection getConnection() {
Connection connection=null;
try {
ClassforName("oraclejdbcOracleDriver");
String url = "jdbc:oracle:thin:@127001:1521:oracle";
String user = "scott";
String password = "tiger";
connection = DriverManagergetConnection(url, user,
password);
} catch (ClassNotFoundException e) {
eprintStackTrace();
} catch (SQLException e) {
eprintStackTrace();
}
return connection;
}
// public static void main(String[] args) {
// JdbcConnection connection=new JdbcConnection();
// connectiongetConnection("asd", "99");
// }
}
第三个类:主类(入口)
package totabeldb;
import javasqlConnection;
import javasqlDriverManager;
import javasqlResultSet;
import javasqlSQLException;
import javasqlStatement;
public class JdbcConnection {
private static JdbcConnection con;
public static JdbcConnection getCon() {
if (con == null) {
con = new JdbcConnection();
}
return con;
}
public Connection getConnection() {
Connection connection=null;
try {
ClassforName("oraclejdbcOracleDriver");
String url = "jdbc:oracle:thin:@127001:1521:oracle";
String user = "scott";
String password = "tiger";
connection = DriverManagergetConnection(url, user,
password);
} catch (ClassNotFoundException e) {
eprintStackTrace();
} catch (SQLException e) {
eprintStackTrace();
}
return connection;
}
// public static void main(String[] args) {
// JdbcConnection connection=new JdbcConnection();
// connectiongetConnection("asd", "99");
// }
}
第四个类:
package totabelxls;
import javaioFile;
import javaioIOException;
import javautilVector;
import javautilregexMatcher;
import javautilregexPattern;
import javaxswingJOptionPane;
import totabelviewTabelData;
import jxlCell;
import jxlSheet;
import jxlWorkbook;
import jxlreadbiffBiffException;
import jxlwriteLabel;
import jxlwriteWritableSheet;
import jxlwriteWritableWorkbook;
import jxlwriteWriteException;
import jxlwritebiffRowsExceededException;
public class ExcelDemo {
/
@param args
/
private Vector title = new Vector();
private Vector[] array;
// public static void main(String[] args) {
// ExcelDemo demo = new ExcelDemo();
// demogetXlsInfo();
//
// }
public void method(TabelData table) {
int row = tablegetRowSize();
int column = tablegetColumnSize();
WritableWorkbook book = null;
Vector title = tablesetTitle();
Object[] str = titletoArray();
try {
book = WorkbookcreateWorkbook(new File("testxls"));
WritableSheet sheet = bookcreateSheet("成绩表", 0);
for (int i = 0; i < strlength; i++) {
sheetaddCell(new Label(i, 0, (String) str[i]));
}
for (int i = 1; i < row + 1; i++) {
for (int j = 1; j < column + 1; j++) {
sheetaddCell(new Label(j - 1, i, tablegetTableInfo(i - 1,
j - 1)));
}
}
bookwrite();
JOptionPaneshowMessageDialog(null, "导出完成!");
} catch (IOException e) {
eprintStackTrace();
} catch (RowsExceededException e) {
eprintStackTrace();
} catch (WriteException e) {
eprintStackTrace();
} finally {
try {
bookclose();
} catch (WriteException e) {
eprintStackTrace();
} catch (IOException e) {
eprintStackTrace();
}
}
}
/
输出Excel的数据到表单
@return
/
public Vector getXlsInfo() {
Vector v = new Vector();
jxlWorkbook rwb = null;
int index = 0;
try {
rwb = jxlWorkbookgetWorkbook(new File("testxls"));
Sheet[] sheet = rwbgetSheets();
for (int i = 0; i < sheetlength; i++) {
int rs = sheet[i]getRows();
array = new Vector[rs - 1];
for (int j = 1; j < rs; j++) {
Cell[] cell = sheet[i]getRow(j);
Vector info = new Vector();
for (int k = 0; k < celllength; k++) {
infoadd(cell[k]getContents());
}
array[index] = info;
index++;
vadd(info);
}
Cell[] titleCell = sheet[i]getRow(0);
for (int j = 0; j < titleCelllength; j++) {
titleadd(titleCell[j]getContents());
}
}
} catch (BiffException e) {
eprintStackTrace();
} catch (IOException e) {
eprintStackTrace();
} finally {
rwbclose();
}
return v;
}
public Vector getXlsInfoToCredit() {
Vector v = new Vector();
jxlWorkbook rwb = null;
try {
rwb = jxlWorkbookgetWorkbook(new File("d:/test/信科0821(南迁)xls"));
Sheet[] sheet = rwbgetSheets();
for (int i = 0; i < sheetlength; i++) {
int rs = sheet[i]getRows();
array = new Vector[rs - 1];
for (int j = 1; j < rs; j++) {
Cell[] cell = sheet[i]getRow(j);
Vector info = new Vector();
for (int k = 0; k < celllength; k++) {
// if(){
Pattern p = Patterncompile("[0-9]{1,}");
Matcher m = pmatcher(cell[k]getContents());
if (mmatches()) {
int score = IntegervalueOf(cell[k]getContents());
float result = getScore(score);
infoadd(result);
} else {
infoadd(cell[k]getContents());
}
}
vadd(info);
}
Cell[] titleCell = sheet[i]getRow(0);
for (int j = 0; j < titleCelllength; j++) {
titleadd(titleCell[j]getContents());
}
}
} catch (BiffException e) {
eprintStackTrace();
} catch (IOException e) {
eprintStackTrace();
} finally {
rwbclose();
}
return v;
}
public float getScore(int n) {
float score = n;
if (n < 60) {
score = 0;
return score;
} else {
if (n >= 60 && n <= 63) {
score = (float) 10;
} else if (n >= 64 && n <= 67) {
score = (float) 13;
} else if (n >= 68 && n <= 71) {
score = (float) 17;
} else if (n >= 72 && n <= 75) {
score = (float) 20;
} else if (n >= 76 && n <= 79) {
score = (float) 23;
} else if (n >= 80 && n <= 83) {
score = (float) 27;
} else if (n >= 84 && n <= 87) {
score = (float) 30;
} else if (n >= 88 && n <= 91) {
score = (float) 33;
} else if (n >= 92 && n <= 95) {
score = (float) 37;
} else if (n >= 96 && n <= 100) {
score = (float) 40;
}
return score;
}
}
public Vector getTitle() {
// getXlsInfo();
return title;
}
public Vector[] getArray() {
getXlsInfo();
return array;
}
}
因为时间问题就没有再写了,上面是我以前做的,不懂就q我Usage: ociuldr user= query= field= record= file=
(@) Copyright Lou Fangxin 2004/2005, all rights reserved
Notes:
-si = enable logon as SYSDBA
user = username/password@tnsname
sql = SQL file name, one sql per file, do not include ";"
query = select statement
field = seperator string between fields
record= seperator string between records
file = output file name(default: uldrdatatxt)
read = set DB_FILE_MULTIBLOCK_READ_COUNT at session level
sort = set SORT_AREA_SIZE & SORT_AREA_RETAINED_SIZE at session level (UNIT:MB)
hash = set HASH_AREA_SIZE at session level (UNIT:MB)
serial= set _serial_direct_read to TRUE at session level
trace = set event 10046 to given level at session level
for field and record, you can use '0x' to specify hex character code,
\r=0x0d \n=0 |=0x7c ,=0x2c \t=0x09
用","来作为字段间的分隔符, 用换行作为记录的分隔符:
E:\tools\developtool\ociuldr>ociuldr user=test/test@mydb query="select from BXLMCHAIN_RAW_N" field=, record=0 file=BXLMCHAIN_RAWtxtORACLE语句将SCOTT用户下的EMP表并进行到处文本文件:
使用SQLPlus的spool命令
*** 作步骤
1
新建一个脚本文件,存放起来,如D:\spoolsql,具体代码如下
:
set echo off --在用start命令执行一个sql脚本时,是否显示脚本中正在执行的SQL语句
set feedback off --是否显示当前sql语句查询或修改的行数
set newpage none --会在页和页之间没有任何间隔
set verify off --
set pagesize 0 --分多少页
set term off --在用spool命令将一个大表中的内容输出到一个文件中时,将内容输出在屏幕上会耗费大量的时间,设置set termspool off后,则输出的内容只会保存在输出文件中,不会显示在屏幕上,极大的提高了spool的速度。
set trims on --将SPOOL输出中每行后面多余的空格去掉
set linesize 600 --设置屏幕显示行宽,默认100
set heading off --禁止输出列标题
set timing off --默认为OFF,设置查询耗时,可用来估计SQL语句的执行时间,测试性能
set numwidth 38
SPOOL D:\aaatxt
select UserTelNo || ',' || to_char(ReceiveTime,'yyyy-MM-dd HH24:MI:SS') || ',' || UserContent || ',' || ReplyContent FROM LogSMSHall_Mutual WHERE rownum<=100;
SPOOL OFF
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)