Je suis un debutant l'extrait de man code est le voici
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 public class testmysql{ public static void main(String[] args){ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","root"); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select col1,col2 from tbl_test"); while (rs.next()){ String s = rs.getString("col1"); String n = rs.getString("col2"); System.out.println(s+" "+n); } rs.close(); stmt.close(); con.close(); } }
et J'ai deja installé tout et meme le driver .jar
J'ai toujours le message d'erreur suivant:
^
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
27
28
29
30 E:\feba\testmysql.java:8: unreported exception java.lang.ClassNotFoundException; must be caught or declared to be thrown Class.forName("com.mysql.jdbc.Driver"); ^ E:\feba\testmysql.java:9: unreported exception java.sql.SQLException; must be caught or declared to be thrown Connection con = DriverManager.getConnection("jdbc:mysql://localhost/test","root","root"); ^ E:\feba\testmysql.java:10: unreported exception java.sql.SQLException; must be caught or declared to be thrown Statement stmt = con.createStatement(); ^ E:\feba\testmysql.java:11: unreported exception java.sql.SQLException; must be caught or declared to be thrown ResultSet rs = stmt.executeQuery("select col1,col2 from tbl_test"); ^ E:\feba\testmysql.java:12: unreported exception java.sql.SQLException; must be caught or declared to be thrown while (rs.next()){ ^ E:\feba\testmysql.java:13: unreported exception java.sql.SQLException; must be caught or declared to be thrown String s = rs.getString("col1"); ^ E:\feba\testmysql.java:14: unreported exception java.sql.SQLException; must be caught or declared to be thrown String n = rs.getString("col2"); ^ E:\feba\testmysql.java:17: unreported exception java.sql.SQLException; must be caught or declared to be thrown rs.close(); ^ E:\feba\testmysql.java:18: unreported exception java.sql.SQLException; must be caught or declared to be thrown stmt.close(); ^ E:\feba\testmysql.java:19: unreported exception java.sql.SQLException; must be caught or declared to be thrown con.close();
Aide moi svp
Merci
Partager