protected String database = null;
protected static final int DB_TYPE_ORACLE = 0;
protected static final int DB_TYPE_SQLSERVER = 1;
- protected static final int DB_TYPE_DB2 = 2;
- protected static final int DB_TYPE_MYSQL = 3;
- protected static final int DB_TYPE_POSTGRESQL = 4;
+ protected static final int DB_TYPE_MYSQL = 2;
+// protected static final int DB_TYPE_DB2 = 3;
+// protected static final int DB_TYPE_POSTGRESQL = 4;
protected static final int DB_TYPE_UNKNOWN = -1;
- protected static final String [] DB_TYPE_NAME = {"ORACLE", "SQLSERVER", "DB2", "MYSQL", "POSTGRESQL"};
+ protected static final String [] DB_TYPE_NAME = {"ORACLE", "SQLSERVER", "MYSQL"};
protected static final int MASK_PTN_ALL = 0;
protected static final int MASK_PTN_ALT = 1;
protected static final int MASK_PTN_EDGE = 2;
"select "
+ " name as table_name "
+ " from sys.tables "
- + " order by name"
+ + " order by name",
+ "select "
+ + " table_name "
+ + " from information_schema.TABLES "
+ + " where TABLE_TYPE = 'BASE TABLE' and TABLE_SCHEMA = database() "
+ + " order by table_name"
};
protected static String [] tkSqlArray = {
"select "
+ "LEFT OUTER JOIN sys.columns AS D "
+ "ON C.object_id = D.object_id "
+ " AND C.column_id = D.column_id "
- + "order by A.name,C.key_ordinal"
+ + "order by A.name,C.key_ordinal",
+ "SELECT "
+ + " a.TABLE_NAME, "
+ + " b.COLUMN_NAME "
+ + " from "
+ + " ( "
+ + " select "
+ + " TABLE_SCHEMA, "
+ + " TABLE_NAME "
+ + " from "
+ + " information_schema.TABLES "
+ + " where TABLE_TYPE = 'BASE TABLE' and TABLE_SCHEMA = database()"
+ + " ) a "
+ + " left outer join information_schema.KEY_COLUMN_USAGE b "
+ + " on a.TABLE_SCHEMA = b.TABLE_SCHEMA "
+ + " and a.TABLE_NAME = b.TABLE_NAME "
+ + " and b.CONSTRAINT_NAME = 'PRIMARY' "
+ + " order by "
+ + " a.table_name,b.ORDINAL_POSITION"
};
protected String user = null;
import java.sql.Blob;
import java.sql.Clob;
import java.math.BigDecimal;
+import java.math.BigInteger;
import java.util.regex.Pattern;
import org.apache.commons.codec.binary.Base64;
}
}
+ protected static void deepPrint(String _message) throws Exception{
+ if(System.getProperty("deep")!=null && System.getProperty("deep").toUpperCase().equals("Y"))System.out.println(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [DEBUG] " + _message);
+ }
+
protected static void debugPrint(String _message) throws Exception{
- if(System.getProperty("debug")!=null)System.out.println(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [DEBUG] " + _message);
+ if(
+ (System.getProperty("deep")!=null && System.getProperty("deep").toUpperCase().equals("Y")) ||
+ (System.getProperty("debug")!=null && System.getProperty("debug").toUpperCase().equals("Y"))
+ )System.out.println(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [DEBUG] " + _message);
}
protected static void debugPrinting(String _message) throws Exception{
- if(System.getProperty("debug")!=null)System.out.print(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [DEBUG] " + _message);
+ if(
+ (System.getProperty("deep")!=null && System.getProperty("deep").toUpperCase().equals("Y")) ||
+ (System.getProperty("debug")!=null && System.getProperty("debug").toUpperCase().equals("Y"))
+ )System.out.print(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date()) + " [DEBUG] " + _message);
}
protected static void infoPrint(String _message) throws Exception{
_str.toUpperCase().equals("VARCHAR2") ||
_str.toUpperCase().equals("NVARCHAR") ||
_str.toUpperCase().equals("NVARCHAR2") ||
- _str.toUpperCase().equals("MVARCHAR") ||
- _str.toUpperCase().equals("BIGINT") ||
- _str.toUpperCase().equals("LONG")){
+ _str.toUpperCase().equals("MVARCHAR")){
return true;
} else {
return false;
}
}
+ protected static boolean isColYear(String _str) throws Exception{
+ if(
+ _str.toUpperCase().equals("YEAR")){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
protected static boolean isColTime(String _str) throws Exception{
if(
_str.toUpperCase().equals("TIME")){
protected static boolean isColShort(String _str) throws Exception{
if(
_str.toUpperCase().equals("TINYINT") ||
+ _str.toUpperCase().equals("TINYINT UNSIGNED") ||
_str.toUpperCase().equals("SMALLINT")){
return true;
} else {
protected static boolean isColInt(String _str) throws Exception{
if(
_str.toUpperCase().equals("INTEGER") ||
+ _str.toUpperCase().equals("SMALLINT UNSIGNED") ||
+ _str.toUpperCase().equals("MEDIUMINT") ||
_str.toUpperCase().equals("INT")){
return true;
} else {
}
}
+ protected static boolean isColLong(String _str) throws Exception{
+ if(
+ _str.toUpperCase().equals("INTEGER UNSIGNED") ||
+ _str.toUpperCase().equals("MEDIUMINT UNSIGNED") ||
+ _str.toUpperCase().equals("BIGINT UNSIGNED") ||
+ _str.toUpperCase().equals("BIGINT") ||
+ _str.toUpperCase().equals("LONG")){
+ return true;
+ } else {
+ return false;
+ }
+ }
+
protected static boolean isColFloat(String _str) throws Exception{
if(
_str.toUpperCase().equals("REAL") ||
protected static boolean isColBytes(String _str) throws Exception{
if(
_str.toUpperCase().equals("RAW") ||
+ _str.toUpperCase().equals("GEOMETRY") ||
_str.toUpperCase().equals("BINARY")){
return true;
} else {
import java.util.Date;
import java.util.ArrayList;
import java.util.Iterator;
+import java.math.BigInteger;
import java.math.BigDecimal;
public class DataAccessObjects{
private String colString = null;
private BigDecimal colBigDecimal = null;
private Integer colInt = null;
+ private Long colLong = null;
private Short colShort = null;
private Float colFloat = null;
private Double colDouble = null;
private java.sql.Timestamp colTimestamp = null;
private java.sql.Time colTime = null;
private java.sql.Date colDate = null;
+ private java.sql.Date colYear = null;
private byte [] colBytes = null;
private Blob colBlob = null;
private Clob colClob = null;
colString = null;
for(int i=0;i<ColumnCount;i++){
colString = getColString(rst, i + 1, colTypeName[i], isNullable[i], false);
+ CmnUtils.debugPrint("col=" + colString);
if (colString != null) {
alData.add(colString);
} else {
}
private String getColString(ResultSet _rst, int _rec_cnt, String _colTypeName, Integer _isNullable, Boolean _colMask) throws Exception{
- String colString = null;
- java.sql.Timestamp colTimestamp = null;
- java.sql.Time colTime = null;
- java.sql.Date colDate = null;
- BigDecimal colBigDecimal = null;
- Integer colInt = null;
- Short colShort = null;
- Float colFloat = null;
- Double colDouble = null;
- byte [] colBytes = null;
- Blob colBlob = null;
- Clob colClob = null;
+ colString = null;
+ colTimestamp = null;
+ colTime = null;
+ colDate = null;
+ colYear = null;
+ colBigDecimal = null;
+ colInt = null;
+ colLong = null;
+ colShort = null;
+ colFloat = null;
+ colDouble = null;
+ colBytes = null;
+ colBlob = null;
+ colClob = null;
ByteArrayOutputStream baos = null;
InputStream is = null;
if (colDate != null) {
colString = colDate.toString();
}
+ } else if (CmnUtils.isColYear(_colTypeName)) {
+ colYear = _rst.getDate(_rec_cnt);
+ if (colYear != null) {
+ colString = colYear.toString().substring(0, 4);
+ }
} else if (CmnUtils.isColTimestamp(_colTypeName)) {
colTimestamp = _rst.getTimestamp(_rec_cnt);
if (colTimestamp != null) {
if (colInt != null) {
colString = colInt.toString();
}
+ } else if (CmnUtils.isColLong(_colTypeName)) {
+ colLong = _rst.getLong(_rec_cnt);
+ if (colLong != null) {
+ colString = colLong.toString();
+ }
} else if (CmnUtils.isColFloat(_colTypeName)) {
colFloat = _rst.getFloat(_rec_cnt);
if (colFloat != null) {
colString = CmnUtils.clobToString(colClob);
}
} else {
- CmnUtils.errorPrint("unmatch column type=" + _colTypeName);
throw new Exception("unmatch column type=" + _colTypeName);
}
return colString;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.math.BigDecimal;
+import java.math.BigInteger;
public class RapideLoader{
private String database = null;
StringBuffer sbColumnName = null;
TABLE_LOOP:
for(int i=0;i<alData.size();i++){
- if(tbName.equals(alData.get(i))){
+ if(tbName.toUpperCase().equals(alData.get(i).toUpperCase())){
if(cp.isInclTables && !CmnUtils.isMatch(cp.inclTablesArray,tbName.toUpperCase())){
CmnUtils.debugPrint("cp.inclTables=" + cp.inclTables);
CmnUtils.debugPrint("table=" + tbName + "," +CmnUtils.isMatch(cp.inclTablesArray,tbName.toUpperCase()));
if(colName[l].equals(colData[j].replaceAll("\"",""))){
if (colIncl[tb_fl_match_count]) {
if (ins_rec_count == 0){
- sql_insert += "\"" + colName[l] + "\"";
+ sql_insert += colName[l];
} else {
- sql_insert += "," + "\"" + colName[l] + "\"";
+ sql_insert += "," + colName[l];
}
tb_col_seq[ins_rec_count]=l;
fl_col_seq[ins_rec_count]=j;
for(int j=0;j<ins_rec_count;j++){
if(j==0){
if(cp.isQuotation){
- colData[fl_col_seq[j]]=colData[fl_col_seq[j]].substring(1,colData[fl_col_seq[j]].length());
+ if(colData[fl_col_seq[j]].length()>1){
+ colData[fl_col_seq[j]]=colData[fl_col_seq[j]].substring(1,colData[fl_col_seq[j]].length());
+ } else {
+ colData[fl_col_seq[j]]=colData[fl_col_seq[j]].substring(1,colData[fl_col_seq[j]].length()).replaceAll("\"","");
+ }
}
}
if(j==ins_rec_count-1){
if(cp.isQuotation){
- colData[fl_col_seq[j]]=colData[fl_col_seq[j]].substring(0,colData[fl_col_seq[j]].length()-1);
+ if(colData[fl_col_seq[j]].length()>1){
+ colData[fl_col_seq[j]]=colData[fl_col_seq[j]].substring(0,colData[fl_col_seq[j]].length()-1);
+ } else {
+ colData[fl_col_seq[j]]=colData[fl_col_seq[j]].substring(0,colData[fl_col_seq[j]].length()).replaceAll("\"","");
+ }
}
}
+
+ CmnUtils.deepPrint("[" + fl_rec_count + "]" + "[" + j + "]" + colName[tb_col_seq[j]].toUpperCase() + "." + colTypeName[tb_col_seq[j]] + "='" + colData[fl_col_seq[j]] + "'");
if (CmnUtils.isColString(colTypeName[tb_col_seq[j]])){
if(cp.isMask){
if(
} else {
stmt_ins.setDate(j+1,null);
}
+ } else if (CmnUtils.isColYear(colTypeName[tb_col_seq[j]])){
+ if (!colData[fl_col_seq[j]].equals("")){
+ stmt_ins.setString(j+1,colData[fl_col_seq[j]]);
+ } else {
+ stmt_ins.setDate(j+1,null);
+ }
} else if (CmnUtils.isColTime(colTypeName[tb_col_seq[j]])){
if (!colData[fl_col_seq[j]].equals("")){
stmt_ins.setTime(j+1,java.sql.Time.valueOf(colData[fl_col_seq[j]]));
} else if (CmnUtils.isColTimestamp(colTypeName[tb_col_seq[j]])){
if (!colData[fl_col_seq[j]].equals("")){
stmt_ins.setTimestamp(j+1,java.sql.Timestamp.valueOf(colData[fl_col_seq[j]]));
+ //CmnUtils.debugPrint("Timestamp=" + colData[fl_col_seq[j]]);
} else {
stmt_ins.setTimestamp(j+1,null);
}
} else {
stmt_ins.setNull(j+1,java.sql.Types.INTEGER);
}
+ } else if (CmnUtils.isColLong(colTypeName[tb_col_seq[j]])){
+ if (!colData[fl_col_seq[j]].equals("")){
+ stmt_ins.setLong(j+1,Long.parseLong(colData[fl_col_seq[j]]));
+ } else {
+ stmt_ins.setNull(j+1,java.sql.Types.BIGINT);
+ }
} else if (CmnUtils.isColFloat(colTypeName[tb_col_seq[j]])){
if (!colData[fl_col_seq[j]].equals("")){
stmt_ins.setFloat(j+1,Float.parseFloat(colData[fl_col_seq[j]]));
CmnUtils.debugPrint("insert record=" + fl_rec_count);
}
}
+ CmnUtils.debugPrint("sql_insert=" + sql_insert);
if(!isLob)stmt_ins.executeBatch();
dao.commit();
System.out.println(String.format("%1$10d",tb_rec_count) + " \8ds \83\8d\81[\83h\82³\82ê\82Ü\82µ\82½\81B");