voici le code complet (tout mache comme sur des roulette)
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class creertab {
/*
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[][] x =new String[100][100];
try {
FileInputStream ips=new FileInputStream("./EXCHO00.csv");
InputStreamReader ipsr=new InputStreamReader(ips);
BufferedReader br=new BufferedReader(ipsr);
String ligne;
int y = 0;
while ((ligne=br.readLine())!=null ) {
String text = ligne;
x[y]=text.split(",");
for (int i=0;i< (x[y].length-2);i++){
System.out.println(x[y][i]);
}
// System.out.println("nouvelle ligne ");
y++;
}
br.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
String URL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/bd1.mdb";
String username = "";
String password = "";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (Exception e) {
System.out.println("Failed to load JDBC/ODBC driver.");
return;
}
Statement stmt = null;
Connection con=null;
try {
con = DriverManager.getConnection (
URL,
username,
password);
stmt = con.createStatement();
} catch (Exception e) {
System.err.println("problems connecting to "+URL);
}
try {
stmt.execute("create table test01 ");
for (int z = 0;z <(x[0].length);z++){
stmt.execute("Alter table test01 add \""+x[0][z]+"\" varchar(50)");
}
for (int z = 1;z <(x.length-2);z++){
String cumul=""+"'"+x[z][0]+"'";
for(int j=1;j<x[z].length;j++){
String str = x[z][j];
cumul=cumul+",'"+str+"'";
}
// System.out.println(cumul);
String s="insert into test01 values ("+cumul+")";
//System.out.println(s);
stmt.execute(s);
}
con.close();
} catch (Exception e) {
System.err.println("problems with SQL sent to "+URL+
": "+e.getMessage());
}
}
}
voici le code complet (tout mache comme sur des roulette)
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStreamReader; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; public class creertab { /* * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String[][] x =new String[100][100]; try { FileInputStream ips=new FileInputStream("./EXCHO00.csv"); InputStreamReader ipsr=new InputStreamReader(ips); BufferedReader br=new BufferedReader(ipsr); String ligne; int y = 0; while ((ligne=br.readLine())!=null ) { String text = ligne; x[y]=text.split(","); for (int i=0;i< (x[y].length-2);i++){ System.out.println(x[y][i]); } // System.out.println("nouvelle ligne "); y++; } br.close(); } catch (Exception e) { System.out.println(e.toString()); } String URL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/bd1.mdb"; String username = ""; String password = ""; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch (Exception e) { System.out.println("Failed to load JDBC/ODBC driver."); return; } Statement stmt = null; Connection con=null; try { con = DriverManager.getConnection ( URL, username, password); stmt = con.createStatement(); } catch (Exception e) { System.err.println("problems connecting to "+URL); } try { stmt.execute("create table test01 "); for (int z = 0;z <(x[0].length);z++){ stmt.execute("Alter table test01 add \""+x[0][z]+"\" varchar(50)"); } for (int z = 1;z <(x.length-2);z++){ String cumul=""+"'"+x[z][0]+"'"; for(int j=1;j<x[z].length;j++){ String str = x[z][j]; cumul=cumul+",'"+str+"'"; } // System.out.println(cumul); String s="insert into test01 values ("+cumul+")"; //System.out.println(s); stmt.execute(s); } con.close(); } catch (Exception e) { System.err.println("problems with SQL sent to "+URL+ ": "+e.getMessage()); } } }