IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

connexion a ma base de donnée Oracle


Sujet :

Java

  1. #1
    Membre à l'essai
    Inscrit en
    Novembre 2009
    Messages
    17
    Détails du profil
    Informations forums :
    Inscription : Novembre 2009
    Messages : 17
    Points : 13
    Points
    13
    Par défaut connexion a ma base de donnée Oracle
    Salut,
    Je suis débutant en java, mon projet consiste a la création d’un logiciel avec java sous jbuilder, j’ai arrivé de crée une interface graphique mais je n’ai pas trouvé comment je peux faire une connexion a ma base de donnée Oracle quand je clic sur le bouton (OK)
    SE : XP
    Base de donnée : login : system
    mot de passe : mabrouk


    package nestedlayouts;

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;

    public class Cadre1 extends JFrame {
    JPanel contentPane;
    XYLayout xYLayout1 = new XYLayout();
    JPanel haut = new JPanel();
    JPanel milieu = new JPanel();
    JPanel barreétat = new JPanel();
    XYLayout xYLayout2 = new XYLayout();
    JPanel barreoutils_gauche = new JPanel();
    JPanel barreoutils_droite = new JPanel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JButton jButton3 = new JButton();
    GridLayout gridLayout1 = new GridLayout();
    GridLayout gridLayout2 = new GridLayout();
    JTextField jTextField1 = new JTextField();
    XYLayout xYLayout3 = new XYLayout();
    JTextArea jTextArea1 = new JTextArea();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();

    //Construire le cadre
    public Cadre1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    }
    catch(Exception e) {
    e.printStackTrace();
    }
    }

    //Initialiser le composant
    private void jbInit() throws Exception {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setAlignmentY((float) 0.5);
    contentPane.setBorder(BorderFactory.createRaisedBevelBorder());
    contentPane.setRequestFocusEnabled(true);
    contentPane.setLayout(xYLayout1);
    this.setSize(new Dimension(636, 401));
    this.setTitle("Disposition Imbriqué");
    barreétat.setBackground(Color.gray);
    barreétat.setBorder(BorderFactory.createRaisedBevelBorder());
    milieu.setBackground(Color.gray);
    milieu.setBorder(BorderFactory.createRaisedBevelBorder());
    milieu.setLayout(xYLayout3);
    haut.setBackground(Color.gray);
    haut.setBorder(BorderFactory.createRaisedBevelBorder());
    haut.setLayout(xYLayout2);
    barreoutils_gauche.setBorder(BorderFactory.createRaisedBevelBorder());
    barreoutils_gauche.setLayout(gridLayout1);
    barreoutils_droite.setBorder(BorderFactory.createRaisedBevelBorder());
    barreoutils_droite.setLayout(gridLayout2);
    jButton1.setMargin(new Insets(2, 2, 2, 2));
    jButton1.setText("OK");
    jButton1.addActionListener(new Cadre1_jButton1_actionAdapter(this));
    jButton2.setMargin(new Insets(2, 2, 2, 2));
    jButton2.setText("Annuler");
    jButton3.setMargin(new Insets(2, 2, 2, 2));
    jButton3.setText("Aide");
    gridLayout1.setHgap(2);
    jLabel1.setFont(new java.awt.Font("Dialog", 1, 18));
    jLabel1.setForeground(Color.white);
    jLabel1.setText("ID_USINE :");
    jLabel2.setFont(new java.awt.Font("Dialog", 1, 18));
    jLabel2.setForeground(Color.white);
    jLabel2.setText("NOM USINE :");
    jTextField1.setText("");
    jTextField1.addActionListener(new Cadre1_jTextField1_actionAdapter(this));
    jTextArea1.setText("");
    contentPane.add(haut, new XYConstraints(15, 7, 597, 54));
    haut.add(barreoutils_gauche, new XYConstraints(6, 6, 466, 40));
    barreoutils_gauche.add(jButton1, null);
    barreoutils_gauche.add(jButton2, null);
    haut.add(barreoutils_droite, new XYConstraints(503, 6, 85, 40));
    barreoutils_droite.add(jButton3, null);
    contentPane.add(milieu, new XYConstraints(15, 77, 600, 256));
    milieu.add(jTextField1, new XYConstraints(200, 14, 376, 53));
    milieu.add(jTextArea1, new XYConstraints(200, 108, 376, 51));
    milieu.add(jLabel1, new XYConstraints(34, 24, 117, 45));
    milieu.add(jLabel2, new XYConstraints(29, 105, -1, 52));
    contentPane.add(barreétat, new XYConstraints(13, 347, 604, 44));
    }

    //Redéfini, ainsi nous pouvons sortir quand la fenêtre est fermée
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    }
    }

    void jTextField1_actionPerformed(ActionEvent e) {

    }

    void jButton1_actionPerformed(ActionEvent e) {

    }
    }

    class Cadre1_jTextField1_actionAdapter implements java.awt.event.ActionListener {
    Cadre1 adaptee;

    Cadre1_jTextField1_actionAdapter(Cadre1 adaptee) {
    this.adaptee = adaptee;
    }
    public void actionPerformed(ActionEvent e) {
    adaptee.jTextField1_actionPerformed(e);
    }
    }

    class Cadre1_jButton1_actionAdapter implements java.awt.event.ActionListener {
    Cadre1 adaptee;

    Cadre1_jButton1_actionAdapter(Cadre1 adaptee) {
    this.adaptee = adaptee;
    }
    public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
    }
    }
    Merci d’avance

  2. #2
    Membre actif Avatar de DarkMolo
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    207
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : Maroc

    Informations forums :
    Inscription : Juillet 2006
    Messages : 207
    Points : 277
    Points
    277
    Par défaut
    Salut,

    Tu as cherché sur la FAQ ?
    Certified SCJP 5.0 / SCWCD 5.0 / SCEA 5.0
    C'est une grande folie de vouloir être sage tout seul.
    Duc de La Rochefoucauld

  3. #3
    Membre à l'essai
    Inscrit en
    Novembre 2009
    Messages
    17
    Détails du profil
    Informations forums :
    Inscription : Novembre 2009
    Messages : 17
    Points : 13
    Points
    13
    Par défaut
    Citation Envoyé par DarkMolo Voir le message
    Salut,

    Tu as cherché sur la FAQ ?
    oui mais j'ai pas trouvé une chose claire qui peut m'aider;
    si tu peut me proposer une solution

  4. #4
    Membre actif Avatar de DarkMolo
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    207
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : Maroc

    Informations forums :
    Inscription : Juillet 2006
    Messages : 207
    Points : 277
    Points
    277
    Par défaut
    Je crois que dans ton cas, avec Oracle, ça ressemblerait à ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:oracle:thin@://localhost:8000:maBase";
    String login = "login";
    String password = "password";
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Connection connection = null;
    try{
       Class.forName(driver);
       connection = DriverManager.getConnection(url,login,password);
       //...
       connection.close();
    }
    catch(ClassNotFoundException cnfe){
       System.out.println("Driver introuvable : ");
       cnfe.printStackTrace();
    }
    Certified SCJP 5.0 / SCWCD 5.0 / SCEA 5.0
    C'est une grande folie de vouloir être sage tout seul.
    Duc de La Rochefoucauld

  5. #5
    Membre à l'essai
    Inscrit en
    Novembre 2009
    Messages
    17
    Détails du profil
    Informations forums :
    Inscription : Novembre 2009
    Messages : 17
    Points : 13
    Points
    13
    Par défaut
    Citation Envoyé par DarkMolo Voir le message
    Je crois que dans ton cas, avec Oracle, ça ressemblerait à ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:oracle:thin@://localhost:8000:maBase";
    String login = "login";
    String password = "password";
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Connection connection = null;
    try{
       Class.forName(driver);
       connection = DriverManager.getConnection(url,login,password);
       //...
       connection.close();
    }
    catch(ClassNotFoundException cnfe){
       System.out.println("Driver introuvable : ");
       cnfe.printStackTrace();
    }
    mais ou je doit mettre ce code??

Discussions similaires

  1. connexion a une base de données oracle + JSP
    Par aminoa dans le forum Servlets/JSP
    Réponses: 13
    Dernier message: 20/07/2016, 13h23
  2. Connexion avec une Base de donnée oracle
    Par zyanya dans le forum VB.NET
    Réponses: 3
    Dernier message: 20/05/2010, 17h45
  3. Connexion pool à une base de données Oracle
    Par karami dans le forum JDBC
    Réponses: 5
    Dernier message: 08/11/2007, 15h17
  4. Réponses: 4
    Dernier message: 25/11/2005, 19h58
  5. connexion a plusieurs bases de données oracle
    Par tarik75 dans le forum JDBC
    Réponses: 1
    Dernier message: 06/07/2005, 13h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo