connecter une application java avec une bd access
Bonjour à tous j'ai esséyé d'écrire un programme java qui me permettrai de me connecter à une base de données access le voici:
import java.sql.*;
import java.awt.*;
import java.util.*;
public class Applic
{
public static void main (String args [])throws Exception
{
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); }
catch (Exception e) { System.out.println("Can't load JDBC Driver. Make sure classpath is correct"); return; }
String url = "jdbc:odbc:ncim";
String username = "";
String password = "";
Connection con;
try { con= DriverManager.getConnection(url, username, password); }
catch (SQLException e) { System.out.println("Connect problem: " + e.getMessage()); return; }
try { Statement stt= con.createStatement();
ResultSet rs= stt.executeQuery("select * from produit");
rs.next();
String id = rs.getString(2);
Frame fen = new Frame ("Bonjour" );
fen.setBounds(100,100,250,150);
fen.setLayout(new FlowLayout( ));
TextField textField1 = new TextField( );
textField1.setBackground(Color.white);
textField1.setBounds(82, 115, 198, 23);
textField1.setText(id);
fen.add(textField1);
fen. setVisible ( true );
stt.close();
con.close();
}
catch (SQLException e) { System.out.println("An SQLException occurred: " + e.getMessage());}
catch (Exception e) { e.printStackTrace(System.err); }
}
un message d'erreur s'affiche:
erreur sql:java.sql.SQLException: No data found
sachant que la configuration de bd sous windows est faite normalement