Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

jammy chen

+ Follow
since Aug 24, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by jammy chen

Campbell Ritchie wrote:I do not think Java Concurrency in Practice is a beginner’s book.Nor is Effective Java.

Yes, it's a little bit difficult for just a beginner, but I do believe it is good book for Java developers, whatever, as a beginner, you can first start with thinking in java and then Java Concurrency in Practice and Effective Java
5 years ago

Armando Moncada wrote:Hi,

I was a COBOL programmer for many years. Now I want to learn JAVA. Which beginning books are good?

Thinking in Java, Effective Java (2nd Edition) and Java Concurrency in Practice ans so much, from beginning, perhaps, Thinking in Java is a good choice, here is a good list of valuable books Java Book Recommendations: Top and Best Java Books
5 years ago

Martin Vajsar wrote:
If, on the other hand, you just wanted to overwrite the CLOB with completely new contents, you don't even need to select the old CLOB at all. You could simply create a brand new CLOB in your second method and use that in your UPDATE statement (and omit call to the first method completely).

Yes, I want overwritten the CLOB with completely new contents, I considered a lot that I don't need select the old CLOB, I used oracle.sql.CLOB.createTempory() to create Temporary clob, it works(not clear is it has risk), but my production need to fit different env, I am not sure whether customer are using but from code condition, we might not use oracle jdbc driver, instead, use weblogic driver, the implementation of interface Clob is not oracle.sql.CLOB. it is but I didn't find a way to create Temporary OracleThinClob.

do you have any suggestion?

As you can see, I used two connections individually for opening and updating Clob. from method getClob: firstly I open a connection to read Clob locater and then release the connection, in next method updateClob I updated clob(it will open another connection), my question is that is this fine? no any problem? because I saw a lot of example codes which used the same connection for selecting and updating statment.
I used the following codes to update clob to oracle by using jdbc

after ran above codes, I checked "bbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" was stored in the db, why? it should be "bbbbbbbbbbbbbbbbbb", right? As we can see the later string "bbbbbbbbbbbbbbbbbb" just appended. but I want it to be replaced.

Martin Vajsar wrote:
Updating a row causes that row to be locked. There is absolutely no uncertainty about this. The explicit (FOR UPDATE) row locking is only necessary if the LOB locator has been read using simple SELECT statement, that does not lock the row unless the FOR UPDATE clause is used. If FOR UPDATE would not be used, several sessions (users) might read the same LOB locator and might try to modify it concurrently.

I really appreciated your helps. I have another question, what is difference between PreparedStatement.setCharacterStream and setAsciiStream? I want to update a java string, which includes English\Chinese\Japanese...Characters. Is it ok to Use setCharacterStream?

I think it is OK. I did actually concentrate only on the first method, as it was part of the discussion.

You're in effect updating the lob locator in the row, and the new locator will not be visible outside your transaction until you commit. Moreover, and more importantly, the update does lock the row in the same way a select for update would. So the reason this method does not require an explicit lock is that it is locked implicitly anyway. I'm really sorry for the confusion I've caused.

The way I suggested (update tbl set lob=empty_clob() where ... returning lob into ?) comes somewhere from Oracle's documentation, and maybe (just maybe) it would perform even better. I think that your second method creates a temporary LOB which is then copied to the table's LOB segment when you execute the statement. The method I hinted creates the LOB directly in the table's LOB segment and writes data to it, so no more copying is involved. If your LOB is large, the copying might take some time. I've elaborated on this here. It is well possible that that code could be changed not to require casting to Oracle's classes, but it ties to Oracle anyway by means of the SQL used, so I didn't care.

Thanks for your answer, the second way is really I never used before, so I am very very careful about it so I afraid it occurs unexpected issue. I may worry to much. I guess it does not require an explicit lock because it is locked implicitly or internally anyway. but who can make sure it? You said ". A little known fact is that when updating LOBs in Oracle, the containing row must be locked to prevent concurrent modifications (at least the 10g documentation states this, 11g seems to be a little bit different;" can you post the link to the Oracle manual or any document? sorry about my so much questions.

Martin Vajsar wrote:

Rob Spoor wrote:

Sudheer Bhat wrote:In case 1, you acquire the lock on the row you are updating so that no one else can acquire the lock. So all other interested transactions who may try to update this row has to wait. So the advantage with approach 1, is that you dont have an issue of "lost updates".

If you use explicit transactions, by calling setAutoCommit(false) on the Connection before updating, then commit() after the update, you also get atomic behaviour.

The setAutoCommit(false) is necessary, but might not be sufficient. A little known fact is that when updating LOBs in Oracle, the containing row must be locked to prevent concurrent modifications (at least the 10g documentation states this, 11g seems to be a little bit different; I didn't dig deep in it though). Googling oracle lob update lock row yields some interesting read.

I think creating and inserting new LOB (in the spirit of update tbl set lob=empty_clob() where ... returning lob into ?) instead of overwriting the existing one would not need the row lock, since the newly created lob locator should not be visible outside current transaction. I'm not sure about it, though.

so you means my second way is somehow incorrect updating method?
Mostly we used and still using this way:

As you can see it select firstly and then update, then I thought another way:

this way is simple and performance did a little better. but I am confusing basically very few people did like this, I wonder why?
so I want know is any difference with first way? or it might cannot work properly? any body can share your ideas?

Thanks your guys for taking a look and give suggestion, I actually want to know the second way can work properly?. or has it potential risk?
I have just make some plan to learn Junit and Ant, I have google some Junit tutrial and I want more especially in junit 4. Is everybody have? another question is Junit and TestNG which is best?
7 years ago
I want start or stop jetty from ant script, who can give me a example, I try to google get some use jetty articles but looks it does't work correctly
8 years ago
Could you put properties.setProperty ("", host) directly in your class not within method? If so you should got error messages, But I am also confused there should not shown this messages according by my experience if you real put this code into class scope.
8 years ago
I think program technique is more important than any luaguage which used to communicate, for now if you are writting some machine program perhaps you could not agreen with me, That's sure you can't complete any a runnable piece of program even simple hello example if you have not learn Java. but let' me get a think how to learn Java, more common and popular style is learn from other people, Now the luaguage is only way to communicate.
The Java is used to communicate for humman with machine, the english is used to communicate for human with human, why our ancestor could invent so extremely greate machine called computer, In root it can be used by ourseives to create more valuable products and reduce our cost. For a java devloper, mostly of time we need to create software for customer according by requirement, the question is how to exactly and really get the customer need. this is time for luaguage.
8 years ago
Could you have startuped the remote java application vm?

You must add some additional paramters which follow after java command to let your remote debug is available, for axample: java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 AdminMain, I need to point the 5005 is your port which need build communitcate on it, then you also need to config the remote configration on eclipse, please choose the attach mode. at finnally only is run the vm it will wait the any client with it build socket communication, I think this is no way appear TimeoutException, if also you should check your firewall keep it colsed try again.
8 years ago
This is no way to archieve your goals, you can do nothing excluded is to press the trun-off/down key to open the computers
8 years ago