stu derby

Ranch Hand
+ Follow
since Dec 15, 2005
Merit badge: grant badges
For More
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 stu derby

This is not really a JDBC question. While your example uses a JDBC-created object, the same theory applies to all created objects.

Java is a "garbage collecting" language; the memory space of any object that no longer has any "live" references may at any time be freed. This is managed by one or more threads running concurrently with your application and happens automatically from time to time. The garbage collector also automatically performs some compaction.

When a new object is being created and there isn't sufficient free memory on the heap, the garbage collector will first attempt to reap any dead objects, and if that fails will attempt to expand the heap - up to the maximum specified by the startup parameters on the java process (which may be a default value), and if that fails, will throw a fatal OutOfMemory exception.

Here's a nice introduction:

While there's lots and lots of things for Java gurus to know about garbage collection, at your current level I'd say:
1. don't keep unnecessary references to objects
2. make sure you explicitly close the JDBC resources you open or use a resource pool; in particular, if you expect to use JDBC on a real-world application in a concurrent use environment (such as a web application) you MUST know about connection pooling, whether you use it or not...
3. don't try to outsmart the garbage collector; that's a great way to really screw things up, until you're a real uber-guru
4. if you have any more questions about Java memory management, please move to a more appropriate forum

Originally posted by miguel lisboa:
thanks again, but as for persisting to a text file, is that a poor idea?

Not necessarily.

It can be an advantage to have the persisted state stored in a human-readable, human-modifiable mode, or it can be a sever disadvantage. depends on the app.

If you're not persisting anything particular complex. I've written apps, that gather settings information and used, then on restart use load().

On the other hand, if you need to discourage user poking at the persisted state, or the state is complex or big and you don't want to read it and write it all at once, then using a database can be just thing.

Besides the well-known external databases, such as MySQL, Oracle, and Postgres, be aware that there are now also embeddable JDBC databases, such as HSQL. They're written in java and (can be configured to) run inside your application, thereby avoiding the complication of making program users configure a connection to a database (and possibly having to set one up).

Some people will try to "split the difference" and use an XML file for persistence. While it can work, and even work well, in my experience it's usually better to go with either plain text at one end of the spectrum, or a true database technology like JDBC at the other.

Originally posted by Dakshayani Cc:
what is the exact definition of serialization of objects in java

Paul's answer to your question is a good answer. However, since this is a JDBC forum and "serialization of objects" doesn't have much to do with JDBC, let's also clarify that "serializable transactions" (which is related to JDBC) is something totally different and not at all related to "serialization of objects".
You probably have a bug in your Java code, causing you to bind the wrong data to the variables.

Originally posted by Rajah Nagur:
It is not good practice from performance perspective to hold on to a ResultSet. ResultSet opens a cursor to the database.

True. Just as bad, it also requires you to keep the connection open and allocated for a long time. Database connections are scarce resources too.

Originally posted by Prakash Rao Laknepalli:

Is there any way to copy the contents(fully/partially) one Resultset object to another say, like i want to copy 10th to 20th records of rs1 to rs2.

Not with standard JDBC. ResultSets are not copyable or clonable. It's remotely possible that a particular driver might have methods to allow this, but no driver I'm familiar with does, and there are lots of good technical reasons not to with many databases.

ResultSets should be thought of as a wrapper class around a network connection; in many implementaions, the results are fetched as needed over the network.

Originally posted by rita aiyar:
i wanted 2 know how can i do multiple updates in the database at d same time using JSP.

Set autocommit off
update 1
update 2

You need to be using a database that supports transactionality (or a single-user DB, or a write-locking DB).

Originally posted by Jasiek Motyka:
I wonder if the following SELECT is correct

The strange thing is that the inner select, alone, executes in 60s
but the whole statement as above in only 2s.
Why is that and is it correct?

You're probably not timing what you think you are.

First, on many databases (particularly Oracle), there are 3 phases to processing a query, known as: parse, execute, fetch

"parse" is the work done for query setup, it is effectively the same for both of your queries.

"execute" is the work done to produce the internal result; it is effectively the same for both of your queries. It is dominated by the logical I/O to produce the result; in this case, the inner query, everything else is insignificant.

"fetch" is the work done to get the internal result and put it on the network for you to get; the nested version is going to be substantially faster because the work gets to stop when the rownum limit is reached.

However, with result sets of any size, one of the biggest factors is the network transfer time; I would guess the difference in network I/O accounts for the majority of the difference in the time.

By the way, with some database (such as Oracle), you can improve your network performance by using setFetchSize() of Statement (or PreparedStatement) to make the driver use bigger buffers (some databases already use really big buffers though, find out what yours is using before you play with this).

Originally posted by Sudheer Yeddu:

Some of the tables in my Source Database(HSQL) have reserved words like "USER", "CLOSE", "OPEN"...etc

Some databases allow you to use reserved words (or even mixed-case table names) by quoting the table name. For example:

I don't know enough about the DBs you're using to know if that's helpful.

Usually, if you have to create them with quotes, then you also have to reference them with quotes in your SELECT and INSERT statements.

Originally posted by Binu Sen:
Your table does not have any column called UID....

And if it did, and it was a numeric column, then your SQL is wrong. Don't put quote characters around numeric data, just around character data.

Better yet, use PreparedStatement instead, it's what the grown-up JDBC programmers use (mostly).

Originally posted by Animesh Dutta:
I am using Oracle 9i as my database. In this i have to save some jpg images. How it can be done, can any body help me as this totally new thing for me. If some code or syntax for inserting and retreiving through database will be very useful for me.
Thanx in advance.

You store them in a column of BLOB datatype.

If you're trying to use Oracle BLOBs, then you should take a look at Oracle's example code for them.

All the examples are here:

For the BLOB (and CLOB) example, it's under "JDBC Advanced Samples", called "LOB Datatype". It's a complete working example program.

Originally posted by Shital Supase:
How to insert a record / tuple into the table / relation using select statement.

You don't, the only want to insert is with either the INSERT or the MERGE statement.
17 years ago

Originally posted by Mark Spritzler:
The sequence tables can go to a very very large number,

The maximum Oracle sequence number is 10 ** 27, or

If you use 1 billion (American billion, 10**9) a day, you will run out in a billion billion days.

Most people find that adequate.
17 years ago

Originally posted by Carlos Juan:

I have an application that shows the data based on the search criteria, shows 10 records a time. I have a table with 1000+ records. When I run the following select it returns me the 1st 10

Now if I run the following it does not return me any data

Any help is appreciated. Thanks

Right. The ROWNUM doesn't start increasing until a row is definitely in the final result.

What you waht is:

17 years ago
You need to add the jars to the NetBeans project you're working on; this in turn will add them to the runtime classpath.

If you don't already, you need to understand what a classpath is and that a compile-time and a runtime classpath may be different, and learn that it is set and maintained differently in NetBeans (and many other IDEs) and in stand-alone Java, which in turn is different from a J2EE server environment (JBoss, WebSphere, etc.)