Bonjour,
Je suis utilisateur de Eclipse, débutant en Java, et je souhaite réaliser une application qui puisse conserver les données dans une base de données MySQL.
Ce qui est installé :
- Eclipse JUNO SR1
- Quantum (l'accès aux bases est OK)
- MySQL 5.5
- MySQL connector java 5.1.22 (installé dans le path du projet)
Voici un code de test trouvé sur le net :Brefs extrait du résultats à l'exécution du code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 import java.sql.*; public class sql { public static void main (String [] args) throws ClassNotFoundException, SQLException{ Connection con = null ; Statement sta = null ; ResultSet result = null; System.out.println("line1"); try { System.out.println("line2"); Class.forName("com.mysql.jdbc.Driver"); System.out.println("line3"); String url = "jdbc:mysql://localhost:3306/data"; con = (Connection) DriverManager.getConnection(url,"root","root"); System.out.println("line4"); sta = (Statement) con.createStatement(); String requete = "SELECT nom FROM valeurs"; result = sta.executeQuery(requete); while (result.next()) { System.out.println(result); } }catch(SQLException s){ System.out.println(s.getMessage()); } } }
Il doit me manquer une étape ? Ou autre chose ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 <ConnectionProperties> <PropertyCategory name="Connection/Authentication"> <Property name="user" required="No" default="" sortOrder="-2147483647" since="all versions"> The user to connect as </Property> <Property name="password" required="No" default="" sortOrder="-2147483646" since="all versions"> The password to use when connecting </Property> <Property name="socketFactory" required="No" default="com.mysql.jdbc.StandardSocketFactory" sortOrder="4" since="3.0.3"> The name of the class that the driver should use for creating socket connections to the server. This class must implement the interface 'com.mysql.jdbc.SocketFactory' and have public no-args constructor. </Property> <Property name="connectTimeout" required="No" default="0" sortOrder="9" since="3.0.1"> Timeout for socket connect (in milliseconds), with 0 being no timeout. Only works on JDK-1.4 or newer. Defaults to '0'. </Property> <Property name="socketTimeout" required="No" default="0" sortOrder="10" since="3.0.1"> Timeout on network socket operations (0, the default means no timeout). </Property>
Merci d'avance pour votre aide.
Partager