You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
3.8 KiB
85 lines
3.8 KiB
package de.superx.bin; |
|
import de.superx.common.FileToTableUploader; |
|
import de.memtext.util.GetOpts; |
|
|
|
/* |
|
* @author Daniel Quathamer Projektgruppe SuperX |
|
* upload_records.java |
|
* Dieses Javaprogramm lädt Inhalte einer Datei in eine Tabelle hoch") |
|
* DQ 5.1.2006 Upload vom XML-Dateien möglich |
|
* |
|
*/ |
|
|
|
public class UploadRecords { |
|
private static String usage = |
|
"-------------------------------------\n" |
|
+ "Gebrauch: java de.superx.bin.UploadRecords \n-dbproperties:<Pfad zu db.properties> \n" |
|
+ "-table:<Tabellenname> \n-unl:<Dateipfad Quelldatei>(optional, default ist Tabellenname.unl) \n-delim:<delimiter>(optional, default ist ^) \n-header:<true|false>(optional, mit Feldüberschriften, default ist false)\n" |
|
+ "-mode:<stop|exclude-row>(optional, default is stop) #Bei Fehlerhaften Daten kann das Hochladen gestoppt werden, oder der Datensatz wird übersprungen" |
|
+ "\n-inserts:<false|simple|batch>(optional, default is false) #Bei -inserts:simple und batch werden Die Rohdaten in Insert-sql-Statements übersetzt (nur für Debugging-Zwecke, sehr langsam. Der Modus exclude-field ist darüberhinaus nicht anwendbar)" |
|
+ "\n-encoding:<utf8,ISO-8859-1, default ist System.file.encoding>" |
|
+ "\n---------------------------------------------------"; |
|
|
|
public static void main(String args[]) { |
|
try { |
|
GetOpts.setOpts(args); |
|
String isdrin = |
|
GetOpts.isAllRequiredOptionsPresent("-dbproperties,-table,-unl"); |
|
if (isdrin != null) { |
|
System.err.println("Folgende Optionen fehlen: " + isdrin); |
|
System.err.println(usage); |
|
System.exit(1); |
|
} |
|
FileToTableUploader myUploader=new FileToTableUploader(); |
|
//GetOpts myOpts=new GetOpts(); |
|
if (GetOpts.isPresent("-dbproperties")) |
|
myUploader.setDbpropfile(GetOpts.getValue("-dbproperties")); |
|
if (GetOpts.isPresent("-informat")) |
|
myUploader.setInFormat(GetOpts.getValue("-informat")); |
|
if (GetOpts.isPresent("-table")) |
|
myUploader.setTargetTable( GetOpts.getValue("-table")); |
|
|
|
if (GetOpts.isPresent("-unl")) |
|
myUploader.setSrcFile(GetOpts.getValue("-unl")); |
|
else |
|
myUploader.setSrcFile(myUploader.getTargetTable() + ".unl"); |
|
if (GetOpts.isPresent("-header")) |
|
myUploader.setHeader(GetOpts.getValue("-header").equalsIgnoreCase("true")?true:false); |
|
if (GetOpts.isPresent("-delim")) |
|
myUploader.setDelim(GetOpts.getValue("-delim")); |
|
if (GetOpts.isPresent("-encoding")) |
|
{ |
|
String encodingParam=GetOpts.getValue("-encoding"); |
|
|
|
if(encodingParam != null && !encodingParam.equals("") ) |
|
myUploader.setEncoding(encodingParam); |
|
} |
|
else |
|
myUploader.setEncoding(System.getProperty("file.encoding")); |
|
if (GetOpts.isPresent("-mode")) { |
|
myUploader.setMode(GetOpts.getValue("-mode").toLowerCase()); |
|
|
|
} |
|
if (GetOpts.isPresent("-inserts")) |
|
myUploader.setInserts(GetOpts.getValue("-inserts")); |
|
long jetzt = new java.util.Date().getTime() ; |
|
myUploader.setUploadConnection(myUploader.getConnection(null,myUploader.getDbpropfile())); |
|
String protokoll=myUploader.uploadFile(); |
|
long erstrecht = new java.util.Date().getTime() ; |
|
System.out.println(myUploader.numberOfRows+" lines loaded"); |
|
System.out.println("File "+myUploader.getSrcFile() +" uploaded"); |
|
if(protokoll.equals("")) |
|
protokoll= " in "+(erstrecht-jetzt)/1000 +" Sec."; |
|
System.out.println(protokoll); |
|
|
|
} catch (Exception ex) { |
|
System.err.println("Upload fehlgeschlagen: " + ex); |
|
System.exit(1); |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|