Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with PreparedStatment

18 views
Skip to first unread message

Vinicius Isola

unread,
Jun 1, 2010, 3:47:32 PM6/1/10
to dev-tech-js-...@lists.mozilla.org
I'm getting the following error:
org.mozilla.javascript.EvaluatorException: Cannot convert id to
java.lang.Integer (server_bootstrap_030.Database.js#163)
at
org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:938)
at org.mozilla.javascript.Context.reportRuntimeError(Context.java:994)
....

inside the following script:

database.ps.setParameter = function (ps, sqlType, index, param) {
log.debug('Setting param, SQL Type: ' + sqlType + ', index: ' + index +
', type: ' + (typeof param) + ', value: ' + JSON.encode(param));
switch (sqlType) {
...
case java.sql.Types.INTEGER:
case java.sql.Types.SMALLINT:
ps.setInt(index, param); <-- Here is the error
break;
...
case java.sql.Types.CHAR:
case java.sql.Types.VARCHAR:
case java.sql.Types.LONGVARCHAR:
default:
ps.setString(index, param);
};
};

This is a function that I wrote to set parameters into a
java.sql.PreparedStatement but it is not working because I'm having this
problem converting 'param' that is a number to a java.lang.Integer, as
stated in the exception. The logging statement in the beginning of the
function outputs the following:
Setting param, SQL Type: 4, index: id, type: number, value: 32

Calling java methods with numbers worked in many different places, I don't
know why is not working here.
Any help would be appreciated.
Vinicius Isola

Mark Porter

unread,
Jun 3, 2010, 12:21:29 PM6/3/10
to
This isn't a rhino problem. The hint is here:

"Setting param, SQL Type: 4, index: id, type: number, value: 32 "

Your index should be an int instead of "id". setXXX() expects the
index to be 1-based index of the "?" in the sql string

----------------------------------------------------------
Mark Porter

Myna JavaScript Application Server
Easy web development with server-side JavaScript
http://www.mynajs.org


On Jun 1, 1:47 pm, Vinicius Isola <viniciusis...@gmail.com> wrote:
> I'm getting the following error:
> org.mozilla.javascript.EvaluatorException: Cannot convert id to
> java.lang.Integer (server_bootstrap_030.Database.js#163)
>     at

> org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReport er.java:109)

Vinicius Isola

unread,
Jun 5, 2010, 9:16:27 AM6/5/10
to Mark Porter, dev-tech-js-...@lists.mozilla.org
You're right. I'm sorry I didn't see that.

Thanks for your help.
Vinicius Isola
"Não podemos escolher as consequências, mas podemos escolher nossos atos."

> _______________________________________________
> dev-tech-js-engine-rhino mailing list
> dev-tech-js-...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
>

0 new messages