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
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package essaisqlserveur;
import java.sql.*;
/**
*
* @author Administrateur
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionString ="jdbc:sqlserver://SERVEUR01;database=RIODISQL;user=sa;password=root";
conn = DriverManager.getConnection(connectionString);
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * from [DiRio-Emetteurs DI]");
System.out.println("Activités:");
while (rs.next()) {
String contact = rs.getString("Compteur")+"-"+rs.getString("Nom");
System.out.println(contact);
}
System.out.println("-Fin-");
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
if (rs != null)
try { rs.close(); } catch (Exception e) { }
if (stmt != null)
try { stmt.close(); } catch (Exception e) { }
if (conn != null)
try { conn.close(); } catch (Exception e) { }
}
}
} |
Partager