Commit 8190468a authored by Quxl's avatar Quxl

x

parent aad02a1d
......@@ -16,7 +16,9 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
......@@ -34,10 +36,10 @@ public class DBPort {
this.dataSource = dataSource;
}
public void doImport(File file, String tableName) throws IOException, SQLException, ClassNotFoundException {
public void doImport(File exportFile, String tableName) throws IOException, SQLException, ClassNotFoundException {
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
fis = new FileInputStream(exportFile);
FileChannel channel = fis.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate((int) channel.size());
int i = 1;
......@@ -52,12 +54,12 @@ public class DBPort {
}
}
public void doExport(File file, String sql, Object[] args) throws IOException, SQLException {
if(!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
public void doExport(File exportFile, String selectSql, Object[] args) throws IOException, SQLException {
if(!exportFile.getParentFile().exists()) {
exportFile.getParentFile().mkdirs();
}
FileOutputStream fos = new FileOutputStream(file);
this.doExport(fos, sql, args);
FileOutputStream fos = new FileOutputStream(exportFile);
this.doExport(fos, selectSql, args);
}
public void doExport(OutputStream os, String sql, Object[] args) throws IOException, SQLException {
......@@ -71,20 +73,21 @@ public class DBPort {
}
}
public byte[] doExport(String sql, Object[] args) throws IOException, SQLException {
public byte[] doExport(String selectSql, Object[] args) throws IOException, SQLException {
Connection connection = dataSource.getConnection();
PreparedStatement ps = connection.prepareStatement(sql);
PreparedStatement ps = connection.prepareStatement(selectSql);
if(args != null) {
for (int i = 0; i < args.length; i++) {
Object argObj = args[i];
if (argObj instanceof java.util.Date) {
java.util.Date argDate = (java.util.Date) argObj;
ps.setObject(i + 1, new java.sql.Timestamp(argDate.getTime()));
ps.setObject(i + 1, new Timestamp(((Date) argObj).getTime()));
} else if (argObj.getClass().isEnum()) {
ps.setObject(i + 1, args[i].toString());
} else {
ps.setObject(i + 1, args[i]);
}
}
}
ResultSet resultSet = ps.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
......@@ -104,7 +107,6 @@ public class DBPort {
}
datas.add(rowData);
}
ByteArrayOutputStream bos = null;
GZIPOutputStream gzip = null;
ObjectOutputStream out = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment