Commit 8190468a authored by Quxl's avatar Quxl

x

parent aad02a1d
...@@ -16,7 +16,9 @@ import java.sql.PreparedStatement; ...@@ -16,7 +16,9 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.ResultSetMetaData; import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
...@@ -34,10 +36,10 @@ public class DBPort { ...@@ -34,10 +36,10 @@ public class DBPort {
this.dataSource = dataSource; 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; FileInputStream fis = null;
try { try {
fis = new FileInputStream(file); fis = new FileInputStream(exportFile);
FileChannel channel = fis.getChannel(); FileChannel channel = fis.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate((int) channel.size()); ByteBuffer byteBuffer = ByteBuffer.allocate((int) channel.size());
int i = 1; int i = 1;
...@@ -52,12 +54,12 @@ public class DBPort { ...@@ -52,12 +54,12 @@ public class DBPort {
} }
} }
public void doExport(File file, String sql, Object[] args) throws IOException, SQLException { public void doExport(File exportFile, String selectSql, Object[] args) throws IOException, SQLException {
if(!file.getParentFile().exists()) { if(!exportFile.getParentFile().exists()) {
file.getParentFile().mkdirs(); exportFile.getParentFile().mkdirs();
} }
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(exportFile);
this.doExport(fos, sql, args); this.doExport(fos, selectSql, args);
} }
public void doExport(OutputStream os, String sql, Object[] args) throws IOException, SQLException { public void doExport(OutputStream os, String sql, Object[] args) throws IOException, SQLException {
...@@ -71,18 +73,19 @@ public class DBPort { ...@@ -71,18 +73,19 @@ 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(); Connection connection = dataSource.getConnection();
PreparedStatement ps = connection.prepareStatement(sql); PreparedStatement ps = connection.prepareStatement(selectSql);
for (int i = 0; i < args.length; i++) { if(args != null) {
Object argObj = args[i]; for (int i = 0; i < args.length; i++) {
if (argObj instanceof java.util.Date) { Object argObj = args[i];
java.util.Date argDate = (java.util.Date) argObj; if (argObj instanceof java.util.Date) {
ps.setObject(i + 1, new java.sql.Timestamp(argDate.getTime())); ps.setObject(i + 1, new Timestamp(((Date) argObj).getTime()));
} else if (argObj.getClass().isEnum()) { } else if (argObj.getClass().isEnum()) {
ps.setObject(i + 1, args[i].toString()); ps.setObject(i + 1, args[i].toString());
} else { } else {
ps.setObject(i + 1, args[i]); ps.setObject(i + 1, args[i]);
}
} }
} }
ResultSet resultSet = ps.executeQuery(); ResultSet resultSet = ps.executeQuery();
...@@ -104,7 +107,6 @@ public class DBPort { ...@@ -104,7 +107,6 @@ public class DBPort {
} }
datas.add(rowData); datas.add(rowData);
} }
ByteArrayOutputStream bos = null; ByteArrayOutputStream bos = null;
GZIPOutputStream gzip = null; GZIPOutputStream gzip = null;
ObjectOutputStream out = 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