Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column" Watch "java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column" New topic
Forums: JDBC Oracle/OAS
Author

java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column

TahirAhmad Dar
Greenhorn

Joined: Oct 13, 2012
Posts: 12
using insert , i am able to insert a new picture into this column but when i try to update previous picture it gives exception .


The Java Code goes like this:

try{

PreparedStatement ps=DatabaseConnection.connection.prepareStatement("update register set picture=? where username=(select username from register where username=?)");
ps.setBinaryStream(1, picture.getInputStream(),(int)picture.getSize());


ps.setString(2,userName);

ps.executeUpdate();
DatabaseConnection.connection.commit();

}catch(Exception e)
{
e.printStackTrace();
}
I am getting an exception :

java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1010)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1315)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3657)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeUpdate(OraclePreparedStatementWrapper.java:1350)
at com.its.dao.ItsDao.updatePicForEmployee(ItsDao.java:653)
at com.its.service.ItsService.updatePicForEmployee(ItsService.java:267)
at com.its.controller.ItsController.doGet(ItsController.java:45)
at com.its.controller.ItsController.doPost(ItsController.java:482)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Sorry, just to clarify, what are the datatypes for the 2 columns?

[Edit] I suspect you have posted this in wrong forum, hopefully someone will move it for you.
TahirAhmad Dar
Greenhorn

Joined: Oct 13, 2012
Posts: 12
The data type is blob from picture and varchar2 for userName.

As i said above , i am able to insert the picture in the same table but in update i am getting sqlException as above mentioned.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

What type of variable is picture?
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

It looks like the setBinaryStream call creates a bind variable (parameter in JDBC Terminology) of type LONG, not BLOB. That's strange. I guess that might be caused by using a really old Oracle JDBC driver. Which files did you include in your project as the JDBC driver? (Is it ojdbc5.jar/ojdbc5.jar, or rather ojdbc14.jar or even classes12.jar?)

To determine the version of your driver, you should inspect the MANIFEST.MF file inside the driver's JAR file.
TahirAhmad Dar
Greenhorn

Joined: Oct 13, 2012
Posts: 12
The driver which i am using is ojdbc6.jar
and data type for picture is blob in database and Part in java.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

Doh! I've completely forgotten about the BLOB/CLOB handling in Oracle.

In the past I've posted one possible way to insert/update BLOB/CLOB in Oracle here. It is non-portable (Oracle specific) code. I don't have a portable BLOB/CLOB handling code example at hand.
 
Consider Paul's rocket mass heater.
 
subject: java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column