Programmation en java
Fermé
kanaz
-
3 sept. 2013 à 20:47
zineb_bendella Messages postés 2 Date d'inscription lundi 9 septembre 2013 Statut Membre Dernière intervention 9 septembre 2013 - 9 sept. 2013 à 19:57
zineb_bendella Messages postés 2 Date d'inscription lundi 9 septembre 2013 Statut Membre Dernière intervention 9 septembre 2013 - 9 sept. 2013 à 19:57
Bonjour,
je suis entraine de developper un projet en java et j'ai besoin d'utiliser sql server 2012 comme base de données, mais je ne sais comment connecter cette base de données avec java et plus precisement netbeans 7.2. J'ai besoin d'un code pour pouvoir m'inspirer.Merci à tous.
je suis entraine de developper un projet en java et j'ai besoin d'utiliser sql server 2012 comme base de données, mais je ne sais comment connecter cette base de données avec java et plus precisement netbeans 7.2. J'ai besoin d'un code pour pouvoir m'inspirer.Merci à tous.
A voir également:
- Programmation en java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
- Application de programmation - Guide
3 réponses
BunoCS
Messages postés
15510
Date d'inscription
lundi 11 juillet 2005
Statut
Modérateur
Dernière intervention
20 mars 2025
3 914
3 sept. 2013 à 20:54
3 sept. 2013 à 20:54
Hello,
Essaie de voir si tu trouves ton bonheur dans la partie tuto Java.
Sinon, je t'invite à détailler ta demande dans le forum Java
Essaie de voir si tu trouves ton bonheur dans la partie tuto Java.
Sinon, je t'invite à détailler ta demande dans le forum Java
/*Comme tu aura pu le remarquer ce code n'est pas de moi, le véritable auteur de ce code est cité en haut du code source...
* Fichier com/eteks/test/CalculTotalFactures.java
*
* Les Cahiers du Programmeur Java - Copyright (C) 2003-2012 Emmanuel PUYBARET / eTeks <***@***>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.eteks.test;
import java.sql.*;
import javax.swing.JOptionPane;
class CalculTotalFactures
{
public static void main(String[] args)
{
try
{
// Chargement de la classe du driver JDBC de MySQL
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException ex)
{
JOptionPane.showMessageDialog(null,
"Classe de driver introuvable " + ex.getMessage());
System.exit(0);
}
Connection connexion = null;
Statement instruction = null;
ResultSet resultat = null;
try
{
// Ouverture de la connexion avec MySQL tournant sur la meme machine
connexion = DriverManager.getConnection(
"jdbc:mysql:///test");
instruction = connexion.createStatement();
// Creation de la table FACTURE et de ses enregistrements
instruction.executeUpdate(
"CREATE TABLE FACTURE(CLIENT CHAR(50),"
+ " ARTICLE VARCHAR(255), MONTANT DECIMAL(9,2))");
instruction.executeUpdate(
"INSERT INTO FACTURE (CLIENT, ARTICLE, MONTANT)"
+ " VALUES ('Thomas Durand', 'CDRx10', '6.35')");
instruction.executeUpdate(
"INSERT INTO FACTURE (CLIENT, ARTICLE, MONTANT)"
+ " VALUES ('Sophie Martin', 'PC', '1500')");
instruction.executeUpdate(
"INSERT INTO FACTURE (CLIENT, ARTICLE, MONTANT)"
+ " VALUES ('Sophie Martin', 'Imprimante', '120.5')");
// Recherche dans la table FACTURE et exploitation du resultat
resultat = instruction.executeQuery(
"SELECT ARTICLE, MONTANT FROM FACTURE"
+ " WHERE CLIENT='Sophie Martin'");
String articles = "";
double montantTotal = 0;
// Boucle vraie tant qu'il y a des enregistrements trouves
while (resultat.next())
{
articles += resultat.getString("ARTICLE") + " ";
montantTotal += resultat.getDouble("MONTANT");
}
JOptionPane.showMessageDialog(null,
"Articles : " + articles
+ "\nMontant total : " + montantTotal + " \u20ac");
// Suppression de la table FACTURE
instruction.executeUpdate("DROP TABLE FACTURE");
}
catch (SQLException ex)
{
JOptionPane.showMessageDialog(null,
"Erreur JDBC : " + ex.getMessage());
}
finally
{
try
{
if (resultat != null)
resultat.close();
if (instruction != null)
instruction.close();
if (connexion != null)
connexion.close();
}
catch (SQLException ex)
{
ex.printStackTrace ();
}
}
}
}
J'espère que ce code pourra t'aider :)
zineb_bendella
Messages postés
2
Date d'inscription
lundi 9 septembre 2013
Statut
Membre
Dernière intervention
9 septembre 2013
9 sept. 2013 à 19:57
9 sept. 2013 à 19:57
3 sept. 2013 à 21:10
Si c'est pour faire un doublon je ne vois pas l'intérêt... la réponse n'ira pas plus vite sur CS !
5 sept. 2013 à 16:44
Désolé, loin de moi l'idée de faire de la "pub"...
C'est juste que j'ai eu à mettre à jour des tutos Java et que j'en ai vu qui parlait de ce que kanaz recherchais, donc je partage l'info ;)
N'y voit aucune malveillance de ma part.