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
|
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
import java.lang.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.Image.*;
import java.sql.*;
import java.lang.Math.*;
import java.util.GregorianCalendar;
import javax.swing.border.*;
import java.io.*;
import java.net.*;
/**
*
* @author Administrateur
*/
public class jdbc {
public static void main(String args[]) throws ClassNotFoundException{
int i;
i=0;
//Connect m=new Connect();
/* Connection con=DriverManager.getConnection();*/
//Connection con = null;
try{ /** Etape 1: charger le pilote */
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
//JOptionPane.showMessageDialog(null,"Premiere etape ça marche");
/** Etape 2: Etablissement de la connexion la base de donnes */
//Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost/workflow","","");//";user=MyUserName;password=*****");
// Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost/workflow");//";user=MyUserName;user=*****");
String connectionUrl = "jdbc:sqlserver://localhost;workflow;dbo";
Connection con1=DriverManager.getConnection(connectionUrl);
//Connection con = DriverManager.getConnection("jdbc:mysql://localhost/new_db","root","");//mysql:localhost:new_db");
JOptionPane.showMessageDialog(null, "Connection OK");
/** Création de mon statement qui va me permettre d'executer mes requetes***/
Statement instruction = con1.createStatement();
//Ma table s'appelle superviseur et tout ce qui reste dépend d'elle
//Vous devez changer certaines infos comme le nom de la table et celui des colonnes
ResultSet resultat = instruction.executeQuery("SELECT * FROM Superviseur");
while (resultat.next()) {i++;
System.out.print("le modele numero"+" "+ i + "");
System.out.println(resultat.getString("id_model"));
}
//System.out.println(resultat);
}
catch(SQLException ex){
JOptionPane.showMessageDialog(null, "coucou");
//ex.printStackTrace(); /
}
}
//System.exit(0);
} |
Partager