How to update oracle Oracle by using JDBC
Mostly we used and still using the following way, as well as it was recommended by oracle official document.
String empty_string = "need to be updated";
conn = getConnection();
pStmt = conn.prepareStatement("SELECT REFERENCE FROM activity WHERE ID = ? FOR UPDATE");
pStmt.setLong(1, 1);
rset = pStmt.executeQuery();
Clob clob = null;
while (rset.next()) {
clob = rset.getClob(1);
Writer writer = adapter.getCharacterOutputStream(clob);
writer.write(empty_string);
writer.flush();
writer.close();
pStmt = conn.prepareStatement("update activity set REFERENCE = ? WHERE ID = ?");
pStmt.setClob(1, clob);
pStmt.setLong(2, 1);
pStmt.executeUpdate();
Now I want use the second way as below, to be honest I never used it before so I wonder can it work properly? as it did not require an explicit lock. will it bring potential risk? according your experience if it work well, which did better performance?
1. String toBeUpdated = "need to be updated";
2. StringReader clob = new StringReader(toBeUpdated );
3. pStmt = conn.prepareStatement("update activity set REFERENCE = ? WHERE ID = ?");
4. pStmt.setCharacterStream(1, clob, toBeUpdated.length());
5. pStmt.setLong(2, 1);
6. pStmt.executeUpdate();
Welcome to the vast OTN forums!
If you are asking about jdbc specifically, perhaps the relevant forum is: {forum:id=1050}.
If what you really are asking is something like (without java code and context):
"I used to do Select.. for update, followed by update table .... Can I instead use only update table ... ? When and why would you use one or the other?"
Then this forum might be ok, but the SQL and PL/SQL forum might be even better: {forum:id=75}
Similar Messages
-
How to implement Oracle DWH using JDBC
Hello,
i'm new to the Oracle database and i'm wondering how to implement a DWH Core or Datamart System using Oracle 11g Express. How can i "switch" a relational oracle database to a dimensional one, preparing it for OLAP/BI queries´, preferably using the JDBC interface ?
Thanks a lot!An good introduction to Oracle OLAP is found on the OTN site: Oracle OLAP.
--Ken Chin -
How to access oracle cursors using jdbc (expecting ur earliest reply)
Hi All,
can anyone help me out by giving me an idea or sample code in accessing the cursors that are defined in the oracle... i have to access those cursors using java... Thanks in advance for your reply and time....
RaguI have tried to follow the example from the URL link you provided.
I'm using :
- Oracle 8.1.6/8.1.7
- JDK 1.3.1
I've created:
create or replace package types
as
type cursorType is ref cursor;
end;
create or replace function sp_ListEmp return types.cursortype
as
l_cursor types.cursorType;
begin
open l_cursor for
select ename, empno
from emp
order by ename;
return l_cursor;
end;
Then I have on my code the following:
import java.sql.*;
import oracle.jdbc.driver.*;
String conStatus = "":
String driver_class = "oracle.jdbc.driver.OracleDriver";
String connect_string = "jdbc:oracle:thin:@slackdog:1521:oracle8";
String query = "begin :1 := sp_listEmp; end;";
Connection conn;
Class.forName(driver_class);
conn = DriverManager.getConnection(connect_string, "scott", "tiger");
try{
conStatus = "before prepareCall, ";
CallableStatement cstmt = conn.prepareCall(query);
conStatus = conStatus + "before Register out, ";
cstmt.registerOutParameter(1,OracleTypes.CURSOR);
conStatus = conStatus + "before execute, ";
cstmt.execute();
conStatus = conStatus + "before getObject, ";
ResultSet rset = (ResultSet)cstmt.getObject(1);
while (rset.next ())
System.out.println( rset.getString (1) );
cstmt.close();
} catch (Exception e) {
conStatus = conStatus + e;
System.out.println(conStatus);
What happens is that I am able to successfully compile the code. But when I run the code, it displays:
"before prepareCall, before Register out, SQLException: incompatible types = -10."
What does that mean? Pls point out to me what I did wrong in my code.
Thanks. -
How to update oracle jdbc driver to 11.1.0.7.0 JDBC Drivers
HI,
I got a jdbc exception *" java.lang.ArrayIndexOutOfBoundsException "*.
I have known that it is a Oracle JDBC bug and Oracle BUG number is BUG-6396242.
The problem is too many rows per database transaction and it is fixed at version 11.1.0.7 Oracle JDBC Drivers.
Here is the 11.1.0.7 Oracle JDBC Driver Readme.
http://www.oracle.com/technetwork/database/enterprise-edition/111070-readme-083278.html
and the download
http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-111060-084321.html
My question is :
*1.How to update oracle jdbc drivers with those downloads ?*
(ps. I have replaced ojdbc5_g.jar, ojdbc5.jar, ojdbc6_g.jar, ojdbc6_g.jar in $ORACLE/jdbc, but it did'nt work. )
*2.My Oracle version is 11.1.0.6.0, will it be OK if only update the JDBC driver?*
*3.Do I need to update the jdbc driver where my program runs on the client side ?*
Thanks for answers~ :)Upgrade your database version to 11.1.0.7.
Installation docs are included with all patches and upgrades. -
I can't get oracle MajorVersion using jdbc in 9.2.0.1.0,how can i do and how many oracl version can't get MajorVersion?
thanks,erveryone! online waitingWhat errors are you getting? Can you post the codew you are using to get MajorVersion.
-
How to prevent Oracle from using an index when joining two tables ...
How to prevent Oracle from using an index when joining two tables to get an inline view which is used in an update statement?
O.K. I think I have to explain what I mean:
When joining two tables which have many entries sometimes it es better not to use an index on the column used as join criteria.
I have two tables: table A and table B.
Table A has 4.000.000 entries and table B has 700.000 entries.
I have a join of both tables with a numeric column as join criteria.
There is an index on this column in table A.
So I instead of
where (A.col = B.col)I want to use
where (A.col+0 = B.col)in order to prevent Oracle from using the index.
When I use the join in a select statement it works.
But when I use the join as inline view in an update statement I get the error ORA-01779.
When I remove the "+0" the update statement works. (The column col is unique in table B).
Any ideas why this happens?
Thank you very much in advance for any help.
Regards HartmutI think you should post an properly formatted explain plan output using DBMS_XPLAN.DISPLAY including the "Predicate Information" section below the plan to provide more details regarding your query resp. update statement. Please use the \[code\] and \[code\] tags to enhance readability of the output provided:
In SQL*Plus:
SET LINESIZE 130
EXPLAIN PLAN FOR <your statement>;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);Usually if you're using the CBO (cost based optimizer) and have reasonable statistics gathered on the database objects used the optimizer should be able to determine if it is better to use the existing index or not.
Things look different if you don't have statistics, you have outdated/wrong statistics or deliberately still use the RBO (rule based optimizer). In this case you would have to use other means to prevent the index usage, the most obvious would be the already mentioned NO_INDEX or FULL hint.
But I strongly recommend to check in first place why the optimizer apparently seems to choose an inappropriate index access path.
Regards,
Randolf
Oracle related stuff:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle:
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
NCHAR issue with oracle database using JDBC adapter
Hi,
We have a requirement to develop an XI interface from FTP server(File adapter) to oracle database using JDBC adapter. In the oracle database table few fields are of type NCHAR/NVARCHAR. when we try to insert the character(A,B,c..) values into oracle table fields of type NCHAR/NVARCHAR, we are getting the following error message in the JDBC adapter audit log. IF we pass the numeric value to the same field, then we are able to insert the records successfully.
Unable to execute statement for table or stored procedure. 'IPCSDD_DOWNLOAD_PROCESS' (Structure 'StatementName1') due to java.sql.SQLException: ORA-00904: "P": invalid identifier
2010-10-19 22:29:59 Error JDBC message processing failed; reason Error processing request in sax parser: Error when executing statement for table/stored proc. 'IPCSDD_DOWNLOAD_PROCESS' (structure 'StatementName1'): java.sql.SQLException: ORA-00904: "P": invalid identifier
2010-10-19 22:29:59 Error MP: Exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'IPCSDD_DOWNLOAD_PROCESS' (structure 'StatementName1'): java.sql.SQLException: ORA-00904: "P": invalid identifier
Please find the system information below.
Oracle version- 10.2.4
XI version - 3.0/ service pack 19
JDBC driver- oracle.jdbc.driver.OracleDriver
Please suggest.
Thanks,
Venkata
Edited by: Venkata Narayana Eepuri on Oct 21, 2010 12:10 AMDear Venkata Narayana,
Concerning the error, kindly go through the following note :
731 - Collective note: ORA-00904
follow the recommendations mentioned in that and please check if that helps.
Best Regards
Nishwanth -
Error while connecting to Oracle db using jdbc
When I try to execute a java class which has to access data in
the Oracle db using Jdbc connection, get an error --
Appln- pathname/filename is attempting to call the OCI function
(opinit) this function does not exist in ORA72.DLL.
Exit this appln ? Yes or No
Both oracle db & java are on the same PC.Would like to know what
can be done to rectify this.
Thanks.
nullThe OCI driver 7.3 requires the 7.3 OCI to be installed (this is
part of the client required support files or RSF). The particular
call in question wasn't added to the OCI untill 7.3 so it
wouldn't exist in the 7.2 OCI library.
null -
How to connect oracle database using jsf
how to connect oracle database using javaserver faces with connection pooling
Here is one way...
http://jakarta.apache.org/commons/dbcp/ -
Inserting Multiple Images into oracle database using JDBC
I wanted to insert multiple images into database using JDBC by reading it from the file... and i am passing photos.txt(my text file) as an input parameter... I have inserted all the values into the database except for the image part... this is my content of photos.txt file and i have copied all the images into the folder
*" C:\\photos "*
*1,in1.jpg,108,19,in-n-out*
*2,in2.jpg,187,21,in-n-out*
*3,in3.jpg,308,41,in-n-out*
*4,in4.jpg,477,52,in-n-out*
*5,in5.jpg,530,50,in-n-out*
and i want to store in1.jpg,in2.jpg,in3.jpg,in4.jpg,in5.jpg into the oracle databse using JDBC.... i have tried a lot using BLOB column.... and i have created my table as
CREATE TABLE PHOTO(
ID NUMBER NOT NULL PRIMARY KEY ,
Name BLOB,
X DOUBLE PRECISION,
Y DOUBLE PRECISION,
Tags VARCHAR2(40)
try { // for restaurant System.out.println();System.out.println();System.out.println(); System.out.print(" Creating Statement for Photo...\n"); stmt2 = con.createStatement (); stmt2.executeUpdate("delete from PHOTO"); stmt2.executeUpdate("commit"); PreparedStatement stmt3 = con.prepareStatement ("INSERT INTO PHOTO VALUES (?, ?, ?, ?, ?)"); System.out.print(" Create FileReader Object for file: " + inputFileName1 + "...\n"); FileReader inputFileReader2 = new FileReader(inputFileName1); System.out.print(" Create BufferedReader Object for FileReader Object...\n"); BufferedReader inputStream2 = new BufferedReader(inputFileReader2); String inLine2 = null; String[] tokens; // String[] imageFilenames = {"c:\\photos\\in1.jpg","c:\\photos\\in2.jpg","c:\\photos\\in3.jpg","c:\\photos\\in4.jpg","c:\\photos\\in5.jpg", // "c:\\photos\\in6.jpg","c:\\photos\\in7.jpg","c:\\photos\\in8.jpg","c:\\photos\\in9.jpg","c:\\photos\\in10.jpg","c:\\photos\\arb1.jpg","c:\\photos\\arb2.jpg", // "c:\\photos\\arb3.jpg","c:\\photos\\arb4.jpg","c:\\photos\\arb5.jpg","c:\\photos\\den1.jpg","c:\\photos\\den2.jpg","c:\\photos\\den3.jpg", // "c:\\photos\\den4.jpg","c:\\photos\\den5.jpg","c:\\photos\\hop1.jpg","c:\\photos\\hop2.jpg","c:\\photos\\hop3.jpg","c:\\photos\\hop4.jpg","c:\\photos\\hop5.jpg"}; File file = new File("C:\\photos\\in1.jpg"); \\ ( Just for example ) FileInputStream fs = new FileInputStream(file); while ((inLine2 = inputStream2.readLine()) != null) { tokens= inLine2.split(","); st2 = new StringTokenizer(inLine2, DELIM); stmt3.setString(1, tokens[0]); stmt3.setBinaryStream(2, fs, (int)(file.length())); stmt3.setString(3, tokens[2]); stmt3.setString(4, tokens[3]); stmt3.setString(5, tokens[4]); stmt3.execute(); //execute the prepared statement stmt3.clearParameters();
As i am able to enter one image file by above code in1.jpg in to the oracle database.... but i am not able to insert all the image file in to the database.....do tell me what should i do.... and can you give me the example on the basis of the above code of mine...
do reply as soon as possible..jwenting wrote:
that depends. Putting the images in BLOBs prevents the file locations stored in the database from getting out of synch with the filesystem when sysadmins decide to reorganise directory structures or "archive" "old" files that noone uses anyway.True, but it really comes down to a business decision (cost-benefit analysis). If you have the bucks, the expertise, and the time, go with the Blobs, otherwise go with the flat files. -
How to update Oracle DB 9.2.0.1 to 9.2.0.3 ?
Execute me, how to update oracle database 9.2.0.1 to 9.2.0.3 ?
My OS is Windows XP , I can't find the db 9.2.0.3 version in download zone .
Please tell me thank you very much .The 9203 patch is not available on OTN. You can download it from metalink(http://metalink.oracle.com) if you have a support contract.
Regards,
Anupama -
How to update java.sql.Clob using javax.persistence.EntityManager?
Hello.
Can anyone tell me (or show me some example) how to update java.sql.Clob using javax.persistence.EntityManager.
When Im trying to update column (with type Clob) value is not inserting, after update column is empty. I havent any error during update, Im using database Oracle 10g.
Edited by: ernest211 on Jul 16, 2009 1:24 AMPost some code so we can see how you are doing it. If you are using JPA entities take a look at the @Lob annotation.
m -
How to update the FB01L transaction using the FM bapi_acc_document_post
Hi All,
How to update the FB01L transaction using the bapi_acc_document_post but there is no ledger group field in the bapi function module.
Please help me how to do it.hi,
use batch input method for the same.
check this.
[https://forums.sdn.sap.com/click.jspa?searchID=19107237&messageID=884744] -
How many messsages can we insert using JDBC receiver adapter in to DB
Hi Friends,
We are having 30 JDBC receiver interfaces in my current implementation project; load of JDBC receiver interfaces was 50 k messages per day and Performing only INSERT operation on data base.
We have created individual communication channel for every JDBC receiver interface and max concurrency value set in CC was 5.
Now we are testing all interfaces in quality with all possible cases, but we found that JDBC receiver adapter unable to process 50 k messages per day, we are on PI 7.1 EHP1 SP7.
Please share your experiences with JDBC adapter receiver like per day how many messages we can transfer.
Thanks a Ton,
RajRaja Sekhar Reddy T wrote:
we are processing 50 k individual messages.
>
> I have increased max threads for JDBC receiver to 20 but no luck same rate only . My questions here is how many messages we can trasfer using JDBC receiver adapter?
>
> Regards,
> Raj
Hi raj,
I have seen some interfaces that deal with upload of 5000 rows at a rime.. I don't there will be a restriction in the no of messages that can be transferred using the JDBC adapter as such unless until the requirement is so para-normal and in your case it is not
Kind regards
XA -
How to update batch (LIPS-CHARG) using FM WS_DELIVERY_UPDATE
Hi guys,
I posted a question regarding a function module here:
How to update batch (LIPS-CHARG) using FM WS_DELIVERY_UPDATE
If you have experience about this FM, kindly visit the link and share your wisdom. Thanks.
Regards,
CarlHi guys,
I posted a question regarding a function module here:
How to update batch (LIPS-CHARG) using FM WS_DELIVERY_UPDATE
If you have experience about this FM, kindly visit the link and share your wisdom. Thanks.
Regards,
Carl -
How to connect Sql Server 2000 using JDBC ODBC Driver
How to connect Sql Server 2000 using JDBC ODBC Driver ?
plz Send Syntax.
thanksIn SQL Server 2000 the driver class is com.microsoft.jdbc.sqlserver.SQLServerDriver
The connection URL for the default SQL Server 2000 database is jdbc:sqlserver://localhost:1433
Class.forName(
"com.microsoft.sqlserver.jdbc.
SQLServerDriver");
String url =
"jdbc:sqlserver://localhost:1433";
Connection conn = DriverManager.
getConnection(
url, "sa", "sqlserver");
Maybe you are looking for
-
Report for list of good receipt document against advance document
Dear all, Good Morning. I want list of pending purchase order in which advace document is created but good receipt document is not created. Like. I have create one purchase order & also create down payment request with F-47. Payment also done by f-48
-
How do I move PSE 8.0 from one computer to another?
I wish to move PSE 8.0 from my old computer to my new one, how do I do this please? I tried activating it with Adobe with the same details as my account, but it hasn't been added to my account. I also looked in System Info in PSE 8.0 to find my seria
-
Why can't I make a purchase from my new IPod using a new credit card which is different from the one I have registered with iTunes before ?
-
Can't display Persian text in JEditorPane
Hi I created html pages with Persian and English text. It displays Persian characters with no problem, however when i get the local html file to display in JEditorPane the Persian chracters appear as ???? can any one help?
-
Multiple PIA/Application servers to one database?
We're planning an upgrade to PT 8.50, FSCM 9.1 and with this upgrade we want to add access for outside customers/vendors. What's the best way to configure an internal employee site/app, and a customer site/app to one production database? Is it as sim