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
| import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import com.mysql.jdbc.ResultSetMetaData;
import com.mysql.jdbc.Statement;
public class connexion {
//private static Connection connect;
static Statement state;
static String[] capteur =new String[11];
static int i =0;
static connexion connec;
static int NBCapteurs;
public static void main(String[] args) {
try {
connec= new connexion();
/*Timer timer = new Timer();
TimerTask task = null;
Date time = null;
timer.schedule(task, time);
{
}, 1000);*/
//insert(215, "192.168.10.1", 3128, 1, 0, 2, 1, "P", 1, 0, "releve");
//select(201);
//nbCapteur();
//changeEcartRouge(20,1);
//changeEcartOrange(25,1);
//changeConsigne(78,2);
//changeReleve(2, 3);
//connec.recup(3);
//connec.delete(3);
//insertTempo(21, "avril", 2012, "21h24", 10, "Alerte", 2);
recupRequete(1);
}
catch (Exception e)
{
// En cas de non connectivité, on prévient par un message que la connexion à échouée
e.printStackTrace();
}
}
public connexion()
{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Driver valide");
String url = "jdbc:mysql://192.168.1.89/Barsun";
String user = "root";
String password = "biscuit";
Connection connect = null;
try
{ Timer timer = new Timer();
timer.schedule (new TimerTask() {
public void run()
{
//System.out.printf ("%tR\n", new Date());
}
}, 10000);
connect = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
// TODO Auto-generated catch block
javax.swing.JOptionPane.showMessageDialog(null,"Erreur de connexion à la base de données !");
e.printStackTrace();
}
try {
state = (Statement) connect.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
System.out.println("Vous êtes connecté à la base de donnée Barsun");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} |
Partager