Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using non-typed Null for PreparedStatement.setObject cause an error with Sybase sql server. #195

Closed
kalinichenko opened this issue Jan 11, 2014 · 10 comments
Assignees
Labels

Comments

@kalinichenko
Copy link
Contributor

kalinichenko commented Jan 11, 2014

java.sql.SQLException: JZ0SE: Invalid object type (or null object) specified for setObject().
    at com.sybase.jdbc4.jdbc.ErrorMessage.raiseError(ErrorMessage.java:765)
    at com.sybase.jdbc4.jdbc.SybPreparedStatement.setObject(SybPreparedStatement.java:1247)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:169)
    at org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:169)
    at scalikejdbc.StatementExecutor$$anonfun$bindParams$3.apply(StatementExecutor.scala:77)
    at scalikejdbc.StatementExecutor$$anonfun$bindParams$3.apply(StatementExecutor.scala:75)
    at scalikejdbc.StatementExecutor.bindParams(StatementExecutor.scala:75)
    at scalikejdbc.StatementExecutor.initialize(StatementExecutor.scala:59)
    at scalikejdbc.StatementExecutor.<init>(StatementExecutor.scala:53)
    at scalikejdbc.DBSession$class.createStatementExecutor(DBSession.scala:65)
    at scalikejdbc.DBSession$class.updateWithFilters(DBSession.scala:308)
    at scalikejdbc.ActiveSession.updateWithFilters(DBSession.scala:420)
    at scalikejdbc.DBSession$class.updateWithFilters(DBSession.scala:290)
    at scalikejdbc.ActiveSession.updateWithFilters(DBSession.scala:420)
    at scalikejdbc.SQLUpdate.apply(SQL.scala:460)
    at models.Employee$.create(Employee.scala:134)
    at models.EmployeeSpec$$anonfun$1$$anonfun$apply$1$$anon$1$delayedInit$body.apply(EmployeeSpec.scala:43)
    at models.EmployeeSpec$$anonfun$1$$anonfun$apply$1$$anon$1.delayedInit(EmployeeSpec.scala:42)
    at models.EmployeeSpec$$anonfun$1$$anonfun$apply$1$$anon$1.<init>(EmployeeSpec.scala:42)
    at models.EmployeeSpec$$anonfun$1$$anonfun$apply$1.apply(EmployeeSpec.scala:42)
    at models.EmployeeSpec$$anonfun$1$$anonfun$apply$1.apply(EmployeeSpec.scala:42)
@ghost ghost assigned seratch Jan 11, 2014
@seratch
Copy link
Member

seratch commented Jan 11, 2014

Oh we must specify java.sql.Types when using #setNull?

http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html#setNull(int, int)

It's difficult to support this for ScalikeJDBC without reducing usability.

@kalinichenko
Copy link
Contributor Author

I'm not sure yet. I will try the same via jtds driver instead of jconn. Second option is specify generic sql type Null. I let you know how it works on Monday when I have an access to sybase sql.

@kalinichenko
Copy link
Contributor Author

kalinichenko commented Jan 14, 2014

So, I checked the case when sql.Types is not specified for null values for sybase (using origin jdbc driver and jtds), mssql and oracle.

I succeed only at doing it in mssql.

Oracle cursed something like this:

[error]    SQLException: : Invalid column type  (DBError.java:180)
[error] oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
[error] oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
[error] oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:285)
[error] oracle.jdbc.driver.OracleStatement.get_internal_type(OracleStatement.java:5465)
[error] oracle.jdbc.driver.OraclePreparedStatement.setNull(OraclePreparedStatement.java:1028)
[error] oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:2311)
[error] oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:2566)
[error] org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:169)
[error] org.apache.commons.dbcp.DelegatingPreparedStatement.setObject(DelegatingPreparedStatement.java:169)

that means the same issue.

Using sybase I tried to use Types.NULL and jtds driver for it but I had no luck either.

@seratch
Copy link
Member

seratch commented Jan 15, 2014

That's strange. ScalikeJDBC basically works with Oracle DB though we don't support it officially. I just tried with Oracle JDBC driver 10.2.0.2 and it's surely possible to pass null value to statements.

@kalinichenko
Copy link
Contributor Author

My fault. I was using an old jdbc driver for Oracle 9i although my server version was 10.2.0.3.0. It definetelly works for oracle.

@seratch
Copy link
Member

seratch commented Jan 15, 2014

OK. I have no plan to support Sybase. I hope Sybase JDBC drivers will start supporting null values for #setObject in the future (as same as Oracle JDBC driver).

@seratch seratch closed this as completed Jan 15, 2014
@kalinichenko
Copy link
Contributor Author

btw, I've checked sybase 15.5 + jtds and it's possible to call setObject without specifying its sql type.

@seratch
Copy link
Member

seratch commented Jan 16, 2014

Cool. I'm glad to hear that.

@dgrene
Copy link

dgrene commented Jun 15, 2017

hi @kalinichenko , could you please tell me how you resolved this issue with sybase.I am still struggling with that

@pariskapoor
Copy link

Hi All,

I had the same issue. In sybase procedure we set as
@contrlnum int = null

While in JAVA callable statement. how to set null by default. We tried setNull, setObject and setString but not working. Any idea please help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants