java.sql.SQLException: ORA-01006

Hi everybody,

I've an issue, and can't find an answer. (I've been searching on google, reading these forums, reading examples, ....) but didn't find my answer.

Here is my problem:

I have an application who needs to update, insert or delete records in an Oracle DB. For the update and delete no issue but for the insert...

here is my code:

publiclong addJob(String rank, String beginValidity, String endValidity){

PreparedStatement psp =null;

long beginV, endV;

SimpleDateFormat sdfParser =new SimpleDateFormat(ContentTypeConstant.DATE_FORMAT);

String sql = DefaultDAO.getSQL(SQL_INSERT);

Connection conn =null;

long returnedId = 0;

try{

conn = getConnection();

psp = conn.prepareStatement(sql);

if (rank ==null){

psp.setNull(1, java.sql.Types.NUMERIC);

}else{

psp.setString(1, rank);

}

if (beginValidity ==null){

psp.setNull(2, java.sql.Types.DATE);

}else{

beginV = sdfParser.parse(beginValidity).getTime();

psp.setDate(2,new java.sql.Date(beginV));

}

if (endValidity ==null){

psp.setNull(3, java.sql.Types.DATE);

}else{

endV = sdfParser.parse(endValidity).getTime();

psp.setDate(3,new java.sql.Date(endV));

}

psp.execute();

sql = DefaultDAO.getSQL(SQL_CURRVAL);

ResultSet rSet = psp.executeQuery(sql);

if (rSet.next()){

logger.debug("Je suis dans le Resultat de JOB=>CURRVAL ");

returnedId = rSet.getLong(1);

}

conn.commit();

psp.close();

rSet.close();

conn.close();

}catch (SQLException e){

logger.error("Last SQL executed " + sql);

logger.warn(e);

}catch (ClassNotFoundException e){

logger.error("Exception " + e);

}catch (ParseException e){

logger.error("Exception " + e);

}

return returnedId;

}

the connection and the incoming parameters are checked.

i have a table named JOB and a trigger that uses the JOB_SEQ.nextval to fill in the id.

But when it execute this code i get:

Last SQL executed insert into job (rank, begin_validity, end_validity) values (?, ?, ?)

be.bvdit.bvdWeb.DAO.JobDAO - java.sql.SQLException: ORA-01006: la variable attache (bind variable) n'existe pas

(it's in french meaning= bind variable does not exists)

or sometimes it says the same message but telling this for

select JOB_SEQ.currval from dual

i forgot to tell:

- SQL_INSERT = insert into job (rank, begin_validity, end_validity) values (?, ?, ?)

- SQL_CURRVAL =select JOB_SEQ.currval from dual

All help will be welcome.

Thanks in advance.

Message was edited by:

Wcfly

Message was edited by:

Wcfly

[4358 byte] By [Wcflya] at [2007-11-27 11:12:47]
# 1

quick answer:

Error: ORA-01006: bind variable does not exist

Cause: You tried to issue a bind call for a variable that was not listed in the corresponding SQL statement.

Action: The options to resolve this Oracle error are:

1. Modify your bind call to reference a variable that was listed in the corresponding SQL statement. Variables must be prefixed with either a colon (:) or an ampersand (&) to be referenced in a BIND call, OBIND, or OBINDN.

2. This error may also be caused by a mismatch between a precompiler program and the SQLLIB library.

java_2006a at 2007-7-29 13:56:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

yes i allready found that, but it didn't help me forward. :-s :-(

but thanks allready for the reply.

Any other suggestion?

Wcflya at 2007-7-29 13:56:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

try this code:

public long addJob(String rank, String beginValidity, String endValidity) {

PreparedStatement psp = null;

long beginV, endV;

SimpleDateFormat sdfParser = new SimpleDateFormat(ContentTypeConstant.DATE_FORMAT);

String sql = DefaultDAO.getSQL(SQL_INSERT);

Connection conn = null;

long returnedId = 0;

try {

conn = getConnection();

psp = conn.prepareStatement(sql);

if (rank == null) {

psp.setNull(1, java.sql.Types.NUMERIC);

} else {

psp.setString(1, rank);

}

if (beginValidity == null) {

psp.setNull(2, java.sql.Types.DATE);

} else {

beginV = sdfParser.parse(beginValidity).getTime();

psp.setDate(2, new java.sql.Date(beginV));

}

if (endValidity == null){

psp.setNull(3, java.sql.Types.DATE);

} else {

endV = sdfParser.parse(endValidity).getTime();

psp.setDate(3, new java.sql.Date(endV));

}

psp.executeUpdate();//CHANGE HERE

sql = DefaultDAO.getSQL(SQL_CURRVAL);

Statement stmt=conn.createStatement();///////// CHANGE HERE

ResultSet rSet = stmt.execute(sql);

if (rSet.next()){

logger.debug("Je suis dans le Resultat de JOB=>CURRVAL ");

returnedId = rSet.getLong(1);

}

conn.commit();

psp.close();

rSet.close();

stmt.close;

conn.close();

} catch (SQLException e) {

logger.error("Last SQL executed " + sql);

logger.warn(e);

} catch (ClassNotFoundException e) {

logger.error("Exception " + e);

} catch (ParseException e) {

logger.error("Exception " + e);

}

return returnedId;

}

hth

java_2006a at 2007-7-29 13:56:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

It would seem odd that you would be getting the ORA-01006 message on a SQL String that doesn't include any placeholders (select JOB_SEQ.currval from dual). This makes me question whether this piece of code is listing the real "Last SQL executed".

> } catch (SQLException e) {

>logger.error("Last SQL executed " + sql);

> logger.warn(e);

This could be just a coding issue with keeping track of which SQL statement is causing the error. If this is a multi-threaded program it could be a synchronization problem between the helper objects and your database access objects.

Just some thoughts...

WorkForFooda at 2007-7-29 13:56:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

Thanks both for replying and for your toughts

I'm not at my office today, but i will test it tomorrow morning.

To the question of a multi-threader problem, it isn't possible, because for the moment i'm the only user of the application.

So i will test the code suggestion tomorrow and keep you informed.

Talk to you later

Thomas

Wcflya at 2007-7-29 13:56:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

it didn't work :'-(

but i also had to change some things you suggested:

psp.executeUpdate();

sql = DefaultDAO.getSQL(SQL_CURRVAL);

Statement stmt = conn.createStatement();

// ResultSet rSet = stmt.execute(sql);

if(stmt.execute(sql)){

ResultSet rSet = stmt.getResultSet();

if (rSet.next()){

logger.debug("Je suis dans le Resultat de JOB=>CURRVAL ");

returnedId = rSet.getLong(1);

}

rSet.close();

}

conn.commit();

psp.close();

conn.close();

I had to change the stmt.execute(sql) because it gives a boolean result.

But i still get the same message

Wcflya at 2007-7-29 13:56:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7

Well if finally seems to work.

I just added the code you gave me.

Thanks sooooooooooooooooooooooooooooo much! Because i really didn't know what to do.

Wcflya at 2007-7-29 13:56:51 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...