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
| public static void creerfichier() throws ClassNotFoundException, IOException
{
Writer out = null;
String pilote="com.microsoft.sqlserver.jdbc.SQLServerDriver";
try {
Class.forName(pilote);
Connection connection = DriverManager.getConnection("jdbc:sqlserver:localhost:1433;databaseName=LIMS_DEV;" + " user=sa ; password=sa ");
java.sql.Statement instruction = connection.createStatement();
String sql = " SELECT * FROM RESULT; ";
instruction.executeQuery(sql);
File file = new File("c:\\write.txt");
out = new BufferedWriter(new FileWriter(file));
out.write(sql);
} catch (FileNotFoundException ex) {
System.err.println("Erreur de fichier non trouver "+ex.getMessage());
} catch (SQLException ex) {
System.err.println("Erreur SQL "+ex.getMessage());
} finally {
out.close();
}
} |
Partager