I tried to insert CLOB in Oracle DB using below code.
I found the below code from this link
but setStringForClob is not available , Please let me know What am doing as Wrong.
am using oracle driver ojdbc14.jar and jdk 1.5
String sql = "insert into table values('abc',123,?)";
OraclePreparedStatement st = (OraclePreparedStatement) connection.prepareStatement(sql);
st.setStringForClob(1, /*String variable which contains the CLOB string*/);
Try getting a newer JDBC driver ojdbc14.jar is really old. Use ojdbc6.jar from oracle.
Related
I'm using Hibernate 5.0.10, Java 7 and Microsoft JDBC Driver 4.1 for SQL Server version 4.1.8112.100.
After changing to Microsoft SQL Server JDBC driver 6.4, I'm getting this error:
Current CallableStatement ou was not a ResultSet, but getResultList was called
It fails on the last line on getResultSet
public List<DocListResultExt> getDocuments(DocList doc) {
StoredProcedureQuery query = entityManagerFactory
.createEntityManager()
.createNamedStoredProcedureQuery("getDocList");
query.setParameter(....);
List<Sp_get_doc_list> spList = (List<Sp_get_doc_list>)query.getResultList();
Any idea why it suddenly seems not compatible with the current code?
Thanks #Mark Rotteveel seem adding SET NOCOUNT ONresolved the issue. Kind of doesn't explain why the driver would handle this differently, but that's ok.
I am trying to create a temporary table inside of AWS redshift using the java SDK.
// Redshift JDBC 4.1 driver: com.amazon.redshift.jdbc41.Driver
String command = "CREATE TABLE test (FirstName varchar(255));"
Class.forName("com.amazon.redshift.jdbc41.Driver");
conn = DriverManager.getConnection(dbURL, props);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(command);
When running this code the table is created successfully but on the return, an error is thrown
com.amazon.dsi.dataengine.impl.DSISimpleRowCountResult cannot be cast to com.amazon.dsi.dataengine.interfaces.IResultSet
Everything will work if I use a command that returns something, such as
"Select * FROM test;"
"SELECT * FROM test LIMIT 0;"
I didn't see any documentation for this problem in the AWS READMEs or other stack overflow questions for this problem. It seems to me that there is a special class in the driver for when nothing is returned from the statement that is not able to be cast to the ResultSet class.
The redshift driver version is 1.1.13.1013 .
Any help would be greatly appreciated!
I had the same problem. You can solve this easily. Instead of
stmt.executeQuery(command);
please try
stmt.execute(command);
My aplication is performing a very simple update on a table :
UPDATE TABLE SET COLUMN = 'XYZ' WHERE PK = 123
The problem is, when Hibernate tries to update the table like this, the table get locked with
ORA event : SQL*Net more data from client.
I tried to replicate the error on my local database but i couldn't.
Does Anybody know what is happening?
Database's version where the error is happening: Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
My local database's version: Oracle Database 10g Release 10.2.0.5.0 - 64bit Production
PS: The column being updated is a CLOB type and the OJDBC driver version is 1.4
Do you know what exactly is being sent to oracle db? I've seen something similar when Hibernate was sending very long sql command and it failed on JDBC driver.
I would suggest starting from getting latest JDBC driver version.
Prepared statement should be used. We should not directly assign the values.
For example:
String updateSQL = UPDATE TABLE SET COLUMN = ? WHERE PK = ? .
PreparedStatement pstmt = null;
pstmt=dbresourceAgent.getPreparedStatement(updateSQL);
pstmt.setString(1,"XYZ");
pstmt.setString(2,"123");
pstmt.executeUpdate();
In jdbc, how to check, that we are using oracle 8i database?
Connection connection = DriverManager.getConnection(url);
DatabaseMetaData meta = connection.getMetaData();
String product = meta.getDatabaseProductName();
String major = meta.getDatabaseMajorVersion();
String minor = meta.getDatabaseMinorVersion();
You might have to use the Database metadata class.
Run:
select * from v$version
It should produce something like:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
...
Then it's just a simple matter of parsing that 1st result row.
this code gives "Incorrectly set or registered parameter" SQLException. Can anyone help please?
OracleConnection conn = getAppConnection();
String q = "BEGIN INSERT INTO tb (id) values (claim_seq.nextval) returning id into :newId; end;" ;
CallableStatement cs = (OracleCallableStatement) conn.prepareCall(q);
cs.registerOutParameter("newId", OracleTypes.NUMBER);
cs.execute();
int newId = cs.getInt("newId");
JDBC does not support named binding, so it stops here.
Either live with indexed placeholders ? or add an extra abstraction layer on top of JDBC which supports named parameters, e.g. Hibernate and/or JPA.
See also:
JDBC tutorial
Hibernate manual, chapter 10.4.1.4 - Bind Parameters
Update: The following is just for documentation purposes but not really usable, since you must set the named parameters in the order they are specified in your sql String. So it works but is very error-prone. Here goes:
I got the same error for a similar constellation using oracle jdbc drivers version 10, but it worked for me after upgrading jdbc drivers to version 11. Version 12.x also works.
My code looks something like this:
int nextIdent;
String sql = "call pkg.do_insert(:NEXT_IDENT, :SOME_COL, ...)";
try (CallableStatement stmt = conn.prepareCall(sql)) {
stmt.registerOutParameter("NEXT_IDENT", Types.INTEGER);
stmt.setString("SOME_COL", "abc");
...
stmt.execute();
nextIdent = stmt.getInt("NEXT_IDENT");
}