slt j'ai une base de donnee access "moteur" et le j'ai fait le code suivant
package Beans
public class Abonne
{
final int id_ab;
private String nom;
private String prenom;
private String login;
private String mot_de_passe;
private Date date_inscription;
private String liste[];
int j,m,a;
public class Date
{
private int j,m,a;
Date(int j,int m,int a)
{
this.j=j;
this.m=m;
this.a=a;
}
int getJ()
{
return(j);
}
int getM()
{
return(m);
}
int getA()
{ return(a);
}
}
public Abonne(String nom, String prenom, String login, String mot_de_passe)
{
id_ab=0;
this.nom=nom;
this.prenom=prenom;
this.login=login;
this.mot_de_passe=mot_de_passe;
this.date_inscription=new Date(j,m,a);
}
public int getId_ab()
{
return(id_ab);
}
public String getNom()
{
return(nom);
}
public void setNom(String nom)
{
this.nom=nom;
}
public String getPrenom()
{
return(prenom);
}
public void setPrenom(String prenom)
{
this.prenom=prenom;
}
public String getLogin()
{
return(login);
}
public void setLogin(String login)
{this.login=login;
}
public String getMot_de_passe()
{
return(mot_de_passe);
}
public void setMot_de_passe(String mot_de_passe)
{this.mot_de_passe=mot_de_passe;
}
public Date getDate_inscription()
{
return(date_inscription);
}
}
et aussi
package Gestionnaire;
import Beans.Abonne;
import Gestionnaire.GestionBD.*;
import java.io.*;
import java.sql.*;
public class GestionAbonne {
/* public int existAbonne(Abonne ab)
{
try
{
String sql;
GestionBD bd=new GestionBD("","","jdbc:odbc:moteur","sun.jdbc.odbc.JdbcOdbcDriver");
bd.Connect();
sql="select * from Abonne where login='"+ab.getLogin()+"' and mot_de_passe='"+ab.getMot_de_passe()+"'";
System.out.println(ab.getLogin());
ResultSet tablAbonne=bd.ExecuteSelect(sql);
int i=0;
while (tablAbonne.next())
{ i++;}
tablAbonne.close();
bd.Disconnect();
if (i==0)
{ return 0;}
else
{return 1;}}
catch(Exception e)
{
System.out.println(e);
return 10;
}
}*/
boolean ok;
public void AddAbonne(Abonne ab)
{
try
{
String sql;
GestionBD bd=new GestionBD("","","jdbc:odbc:moteur","sun.jdbc.odbc.JdbcOdbcDriver");
bd.Connect();
sql="insert into Abonne(nom,prenom,login,mot_de_passe) values ('"+ab.getNom()+"','"+ab.getPrenom()+"','"+ab.getLogin()+"','"+ab.getMot_de_passe()+"')";
ok=false;
ok=bd.ExecuteQuery(sql);
if (ok)
{
System.out.println("Insertion terminee avec succes");
}
else
{
System.out.println("insertion echouee");
}
}
catch(Exception e)
{
System.out.println("erreur d'insertion");}}
/*/public void DeleteAbonne(Abonne ab)
{
try
{
String sql;
GestionBD bd=new GestionBD("","","jdbc:odbc:moteur","sun.jdbc.odbc.JdbcOdbcDriver");
bd.Connect();
sql="delete from Abonne where login='"+ab.getLogin()+"'";
boolean ok=false;
ok=bd.ExecuteQuery(sql);
if (ok)
{
System.out.println("Delete terminee avec succee");
}
else
{
System.out.println("Delete a echouee");
}
}
catch(Exception e)
{System.out.println("erreur de suppression");}
}
/*public void UpdateAbonne(Abonne ab)
{
try{
String sql;
GestionBD bd=new GestionBD("","","jdbc:odbc:moteur","sun.jdbc.odbc.JdbcOdbcDriver");
bd.Connect();
sql="update Abonne nom='"+ab.getNom()+"',Prenom="+ab.getPrenom()+",login="+ab.getLogin()+",Mot_de_passe='"+ab.getMot_de_passe()+"'";
boolean ok=false;
ok=bd.ExecuteQuery(sql);
if (ok)
{
System.out.println("update termine");
}
else
{
System.out.println("update a echoue");
}
}
catch(Exception e){System.out.println("erreur de l'update");}
}
*/
public static void main(String f[])
{
Abonne a=new Abonne("d","n","nnaa","aaaaaaaaa");
GestionAbonne g=new GestionAbonne();
g.AddAbonne(a);
}
}
et
package Gestionnaire;
/**
*
* @author nawal
*/
/*
* GestionBD.java
*
* Created on 1 avril 2008, 20:58
*/
import java.io.*;
import java.sql.*;
public class GestionBD {
String nom;
String motdepasse;
String url="";
String Driver;
Connection con;
Statement statement;
public GestionBD(String nom,String motdepasse,String url,String Driver)
{
this.Driver=Driver;
this.nom=nom;
this.motdepasse=motdepasse;
this.url=url;
this.con=null;
this.statement=null;
}
public void Connect()
{
try
{ Class.forName(Driver);
con=DriverManager.getConnection(url,nom,motdepasse);
statement=con.createStatement();
}
catch(Exception e){System.out.println(e);}
}
public void Disconnect()
{
try
{
statement.close();
con.close();
}
catch(Exception e){}
}
public ResultSet ExecuteSelect(String query)
{
try
{
return (statement.executeQuery(query));
}
catch(Exception e)
{
System.out.println(e);
return null;
}
}
public boolean ExecuteQuery(String query)
{
try
{
statement.executeUpdate(query);
return true;
}
catch(Exception e)
{
System.out.println(e);
return false;
}
}
}
la base est enregistré dans le dossier gestionnaire
a l'execution le message suivant est affiche:
java.sql.SQLException: No data found
java.lang.NullPointerException