Je suis débutant et j'ai voulu utiliser Java avec JDBC avec ACCESS sur une base de données locale :
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
 
import java.sql.*;
public class hello{
 
 
      public static void main(String[] args){
 
          try {
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              }catch (Exception e) {
              System.out.println("Error: " + e);
              }
          String url="jdbc:odbc: Personnes" ; 
          Connection con = DriverManager.getConnection(url,"",""); 
          Statement st = con.createStatement();
          ResultSet rec = st.executeQuery( "select nom from Client");
 
 
      }
 
 
}
Ici : personnes est le nom de la source de données

À la compilation j’ai les messages suivants :

hello.java:13: unreported exception java.sql.SQLException; must be caught or declared to be thrown
Connection con = DriverManager.getConnection(url,"","");
^
hello.java:14: unreported exception java.sql.SQLException; must be caught or declared to be thrown
Statement st = con.createStatement();
^
hello.java:15: unreported exception java.sql.SQLException; must be caught or declared to be thrown
ResultSet rec = st.executeQuery( "select nom from Client");
^
3 errors
Je pense que le problème se situe au niveau de la connexion.
Qu’est ce qu’il faut pour qu’il fonctionne?