• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The index 1 is out of bounds

 
nadia ghezaiel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After running this code I found this exception!!!I don't inderstand what is it???!!!



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Conn;
import java.sql.Connection;
import java.sql.*;
import javax.swing.JOptionPane;

/**
*
* @author Nadia
*/
public class Connexion {

java.sql.Connection C;

//private Connection C1;
String Nom;
String Adresse;
String MDP;
String VMDP;
/**
* Constructeur
*/
public Connexion() {
//this.connection=ConnexionBDD.getInstance();

try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
C= DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=Authentif","sa","nadia");
Statement stmt = C.createStatement();
}

catch(Exception e){}
System.out.println("Erreur de connexion.");
}

//*************Insertion Utilisateur

// public int insertUtilisateur(UserIdentit utilisateur) {


public void insertUtilisateur(String Nom,String Adresse,String MDP,String VMDP) {

PreparedStatement pst;
try {


pst = C.prepareStatement("INSERT INTO Authentif.dbo.tab_authentif (Nom,Adresse,MDP,VMDP)"+"VALUES(?,?,?,?)");
pst.setString(1,Nom);
pst.setString(2,Adresse);
pst.setString(3,MDP);
pst.setString(4,VMDP);
int res=pst.executeUpdate();
} catch (SQLException ex) {

System.out.println("Erreur lors de l'insertion de l'utilisateur.");
JOptionPane.showMessageDialog(null,ex.getMessage());
}


/////A voir Absolument
/*pst = C.prepareStatement(requete);
pst.setString(1,utilisateur.getNom());
pst.setString(2,utilisateur.getAdresseC());
pst.setString(3, utilisateur.getMDP());
pst.setString(4, utilisateur.getVMDP());*/

/* resultat = pst.executeUpdate();
pst.close();
pst = null;
} catch (SQLException e) {
System.out.println("Erreur lors de l'insertion de l'utilisateur.");
e.printStackTrace();
}

return resultat;*/


}

/////***************************Connecter utilisateur********************************
public void seConnecter(String Nom,String MDP)
{
PreparedStatement pst;
try {


pst = C.prepareStatement("SELECT Nom FROM Authentif.dbo.tab_autnentif WHERE Nom='" + Nom + "' AND MDP='"+MDP+"'");
pst.setString(1,Nom);
pst.setString(3,MDP);
int res=pst.executeUpdate();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,ex.getMessage());
}




}
}

j'ai cherché le correctif afin de pour resoudre ce pb mais je n'est pas comprix comment l'excectuer!!!
le correctif est: Hotfix

SVP Aider moi!!!
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please provide an English translation; non-English posts are generally deleted quickly.
 
nadia ghezaiel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nadia ghezaiel wrote:After running this code I found this exception!!!I don't inderstand what is it???!!!



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Conn;
import java.sql.Connection;
import java.sql.*;
import javax.swing.JOptionPane;

/**
*
* @author Nadia
*/
public class Connexion {

java.sql.Connection C;

//private Connection C1;
String Nom;
String Adresse;
String MDP;
String VMDP;
/**
* Constructeur
*/
public Connexion() {
//this.connection=ConnexionBDD.getInstance();

try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
C= DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=Authentif","sa","nadia");
Statement stmt = C.createStatement();
}

catch(Exception e){}
System.out.println("Erreur de connexion.");
}

//*************Insertion Utilisateur

// public int insertUtilisateur(UserIdentit utilisateur) {


public void insertUtilisateur(String Nom,String Adresse,String MDP,String VMDP) {

PreparedStatement pst;
try {


pst = C.prepareStatement("INSERT INTO Authentif.dbo.tab_authentif (Nom,Adresse,MDP,VMDP)"+"VALUES(?,?,?,?)");
pst.setString(1,Nom);
pst.setString(2,Adresse);
pst.setString(3,MDP);
pst.setString(4,VMDP);
int res=pst.executeUpdate();
} catch (SQLException ex) {

System.out.println("Erreur lors de l'insertion de l'utilisateur.");
JOptionPane.showMessageDialog(null,ex.getMessage());
}


/////A voir Absolument
/*pst = C.prepareStatement(requete);
pst.setString(1,utilisateur.getNom());
pst.setString(2,utilisateur.getAdresseC());
pst.setString(3, utilisateur.getMDP());
pst.setString(4, utilisateur.getVMDP());*/

/* resultat = pst.executeUpdate();
pst.close();
pst = null;
} catch (SQLException e) {
System.out.println("Erreur lors de l'insertion de l'utilisateur.");
e.printStackTrace();
}

return resultat;*/


}

/////***************************Connecter utilisateur********************************
public void seConnecter(String Nom,String MDP)
{
PreparedStatement pst;
try {


pst = C.prepareStatement("SELECT Nom FROM Authentif.dbo.tab_autnentif WHERE Nom='" + Nom + "' AND MDP='"+MDP+"'");
pst.setString(1,Nom);
pst.setString(3,MDP);
int res=pst.executeUpdate();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,ex.getMessage());
}




}
}

Microsoft suggest this correction: Hotfix[color=red] [/colorPlease help me!!!
 
Paul Clapham
Sheriff
Posts: 21557
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea what you meant about Microsoft suggesting Hotfix. Was that an error message, or did you try to research the problem and found that on the web somewhere, or what?

Anyway your problem is here:



Earlier in your code you knew how to use a PreparedStatement -- in that one you had 4 question marks representing parameters and you assigned them values from 1 to 4 in the next 4 lines of code. In this one you don't have any question marks but you try to assign a value to the first question mark. There are 0 question marks so you can't assign a value to question mark number 1 -- which means that 1 is out of bounds.
 
nadia ghezaiel
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thinks!!! Mr.Paul
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic