|
|
|
|
Bonjour,
j'ai cette erreur je debute dans la programmation java, apres ma formation j'ai du creer un programme qui se connect à une base sql et qui execute une procedure stocké .Il se connecte bien mais j'ai une erreur
java.lang.NullPointerException at ProcedureStocke .main(ProcedureStocke.java :35)
voici mon programme
import java.sql.*;
import java.lang.*;
public class ProcedureStocke {
public static void main(String[] args) {
// Create a variable for the connection string.
String connectionUrl = "jdbc:odbc:logipro";
//integratedSecurity=false;";
// Declare the JDBC objects.
Connection con =null;
//Statement stmt = null;
ResultSet rs = null;
CallableStatement cstmt=null;
try {
// Establish the connection.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(connectionUrl,"admin","admin");
// Create and execute an SQL statement that returns some data.
String SQL ="{call creation_user}";
cstmt= con.prepareCall (SQL);
cstmt.execute();
//rs = cstmt.executeQuery(SQL);
// Iterate through the data in the result set and display it.
while (rs.next()) {
System.out.println(rs.getString(1) + " " + rs.getString(2));
}
}
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (cstmt != null) try { cstmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}
}
Merci pour votre aide
Configuration: Windows Vista Internet Explorer 7.0
MERCI DE COCHER LE TAG "Résolu" quand le problème est résolu ET de mettre la solution trouvée.
ResultSet rs = null; ... cstmt.execute(); //rs = cstmt.executeQuery(SQL); Donc lorsque tu tente de l'utiliser, ta variable est nulle, donc tu ne peux pas faire appel à une méthode depuis un objet null, donc tu obtient une NullPointerException ici :
// Iterate through the data in the result set and display it.
while (rs.next()) {
~ N'oubliez pas la balise "Résolu" lorsque votre problème est... résolu :) ~ |