Bonjour,
Je cherche un moyen simple de passer en paramètre des objets ou des tableaux de types primitifs (int, double, String ...)
à une procédure stockée via JDBC.
Pour l'instant, j'ai crée une classe conteneur qui implémente l'interface SQLData :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
/**
*
*/
package rdv.modele;
import java.sql.SQLData;
import java.sql.SQLException;
import java.sql.SQLInput;
import java.sql.SQLOutput;
/**
* Timmy.java
* Crée le : 17 avr. 2009
* Classe de test pour le passage d'objets à une procédure stockée
*/
public class Timmy implements SQLData {
public int eric;
public int cartman;
/** le nom du type de données correspondant dans la base */
public String datatype;
/* (non-Javadoc)
* @see java.sql.SQLData#getSQLTypeName()
*/
@Override
public String getSQLTypeName() throws SQLException {
// TODO Auto-generated method stub
return "TIMMY";
}
@Override
public void readSQL(SQLInput stream, String type) throws SQLException {
setEric(stream.readInt());
setCartman(stream.readInt());
setDataType(stream.readString());
}
@Override
public void writeSQL(SQLOutput stream) throws SQLException {
stream.writeInt(getEric());
stream.writeInt(getCartman());
stream.writeString(getDatatype());
}
public int getEric() {
return eric;
}
public void setEric(int eric) {
this.eric = eric;
}
public int getCartman() {
return cartman;
}
public void setCartman(int cartman) {
this.cartman = cartman;
}
public String getType() {
return datatype;
}
public void setType(String type) {
this.datatype = type;
}
public String getDatatype() {
return datatype;
}
public void setDatatype(String datatype) {
this.datatype = datatype;
}
} |
Côté BD (je travaille sous Oracle 10g) dans mon package :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
TYPE TIMMY IS RECORD (
eric NUMBER,
cartman NUMBER,
datatype VARCHAR2(10)
);
FUNCTION test (
objet IN TIMMY
) RETURN NUMBER IS
BEGIN
RETURN 0;
EXCEPTION
WHEN OTHERS
THEN NULL;
ROLLBACK;
RETURN -9;
END; |
J'obtiens une erreur du style :
java.sql.SQLException: Le modèle de nom n'est pas valide: SAV_CPGE.TIMMY
Voilà merci de votre aide
Partager