1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| public void importerClient() throws FileNotFoundException, SQLException
{
try
{
Class.forName("org.relique.jdbc.csv.CsvDriver");
Properties props = new java.util.Properties();
props.put("separator","|");
props.put("fileExtension",".dat");
Connection conn = DriverManager.getConnection("jdbc:relique:csv:C:\\Temp", props);
Statement stmt = conn.createStatement();
ResultSet results = stmt.executeQuery("SELECT noclient,nomcompagnie,adresse1,adresse2,ville,codepostal," +
"telephone,courriel,province,pays,language FROM client");
insertClient(results);
conn.close();
} catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
}
private void insertClient(ResultSet results) throws SQLException
{
Statement stmt = null;
String nom = "";
while (results.next())
{
String noclient = results.getString(1);
String nomcompagnie = results.getString(2);
String adresse1 = results.getString(3);
String adresse2 = results.getString(4);
String ville = results.getString(5);
String codepostal = results.getString(6);
String phone = results.getString(7);
String courriel = results.getString(8);
String province = results.getString(9);
String pays = results.getString(10);
String language = results.getString(11);
/**************************************************/
String langue = "fr";
if (language.compareTo("1")==0)
{
langue = "en";
}
else
{
if (language.compareTo("2")==0)
{
langue = "fr";
}
}
/**************************************************/
String codePays = "CA";
if (pays.compareTo("CANADA")==0)
{
codePays = "CA";
}
else
{
if (pays.compareTo("FRANCE")==0)
{
codePays = "FR";
}
else
{
if (pays.compareTo("SWITZERLAN")==0)
{
codePays = "SW";
}
}
}
/**************************************************/
String codetaxeapplicableclient = "";
if (province.compareTo("QC")==0 | province.compareTo("QUEBEC")==0)
{
codetaxeapplicableclient = "REG";
}
/**************************************************/
String devise = "CAD";
if (pays.compareTo("USA")==0)
{
devise = "USD";
}
else
{
if (pays.compareTo("FRANCE")==0 | pays.compareTo("SWITZERLAN")==0)
{
devise = "EUR";
}
}
/**************************************************/
stmt = DatabaseManager.execute("INSERT INTO client (noclient, nomcompagnie, adresse1, adresse2, ville," +
" codepostal, telephone, courriel, province, codepays," +
" codetaxeapplicableclient, devise, langue) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
noclient, nomcompagnie, adresse1, adresse2, ville, codepostal, phone, courriel,
province, codePays, codetaxeapplicableclient, devise, langue);
System.out.println("******stmt******"+stmt);
}
results.close();
stmt.close();
} |
Partager