Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void enregistrer(int a, int b) {
- try {
- Class.forName( "com.mysql.jdbc.Driver" ); // Chargement du driver JDBC pour MySQL
- } catch (ClassNotFoundException e1) {
- e1.printStackTrace();
- }
- /* Connexion à la base de données */
- String url = "jdbc:mysql://localhost:3306/jee";
- String utilisateur = "root"; //sur phpMyAdmin, le nom d'utilisateur doit être "root"
- String motDePasse = ""; // et il ne faut pas utiliser un mot de passe
- Connection connexion = null;
- Statement statement = null;
- try {
- connexion = DriverManager.getConnection( url, utilisateur, motDePasse );
- /* Création de l'objet gérant les requêtes */
- statement = (Statement) connexion.createStatement();
- /* Exécution d'une requête d'insértion */
- statement.executeUpdate("insert into tab(a,b) values("+a+","+b+");");
- } catch ( SQLException e ) {
- System.out.println(e.getMessage());
- }
- finally {
- if ( statement != null ) {
- try {
- statement.close();
- } catch ( SQLException ignore ) {
- }
- }
- if ( connexion != null ) {
- try {
- connexion.close();
- } catch ( SQLException ignore ) {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement