It depends on the SQL backend you're using, and how sincere you are.
Basically, you'd want to convert every single quote to be
double-single-quotes (i.e., O'Donnell becomes O''Donnell), which means
writing a custom function.
That's ugly, and unnecessary. (Aren't you glad?)
If you use PreparedStatements, the JDBC driver will escape all data for you,
for the specific database you're using. (This is important, as some DBs don't
follow the "double single-quotes" rule mentioned above.) Example code:
PreparedStatement ps=conn.prepareStatement("insert into names values (?)");
ps.setString(1, "O'Donnell");
ps.executeUpdate();
Reproduced with permission of http://java.enigmastation.com/index The
Undernet #Java Knowledge Base
... (more)
If you already have your ResultSet, you have two choices, both bad: one is to
keep a counter as you read the records in the ResultSet, and the other is to
hope you have a compliant JDBC driver that supports the getRowCount() method.
Both ways probably do the same thing: read the entire dataset. If you're
interested in only a count of records, that's a lot of bandwidth down the
drain (and... (more)
It's with continued amusement that I constantly read about how Java should be
defended from .NET, and how .NET will destroy Java. I understand the
invective used by both sides, but the shine is starting to wear off; it's
time to stop hurling insults, and examine what the future really holds. In my
opinion, Java and .NET don't truly compete on a meaningful technological
front - because bo... (more)
As I look over my choices for various tasks, I'm a little unsettled at how
many choices I have, what they do, and how they interoperate. I'm not going
to be the one to say that innovation is a bad thing, but too much innovation
probably is a bad thing. In software design, it usually means the innovator
hasn't looked into appropriate technology enough to know how to use what's
available, ... (more)
In my last editorial (Vol. 8, issue 6), I argued that we, as an industry,
have too much innovation. We have solutions pouring out our ears, stuff we
often don't need, yet we use it anyway. This month, I'd like to clarify that
somewhat: we need more innovation.
The seeds for innovation are already present: new projects are fertile
ground. The problems are often unique, so the solutions tha... (more)