Categories
Java SQL Server

Counting how many rows were returned by a JDBC ResultSet

After executing a JDBC query, you often want to know if anything was returned and if so how many rows exist in the ResultSet. To do that, use this snippet of code:


ResultSet rs = st.exeuteQuery();
rs.last();
int rsRowCount = rs.getRow();
rs.beforeFirst();

The rsRowCount variable will have the answer.
Make sure that your Statement or PreparedStatenent are created using the three parameter version of the Connection object methods createStatement() and PrepareStatement() like:
Statement statement =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

OR

PreparedStatement ps = conn.prepareStatement([SQL EXPRESSION],
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);

Look at
the JavaDoc entry for this method.

Share
Categories
Computing Java SQL Server

DB2 Impressions

When I got my laptop at my new job it did not have a DBMS installed. Sad, but could be worse. Since the only free version of SQL Server is the MSDE, and the Oracle ‘personal’ edition is almost a gigabyte-sized download, I decided to check out the personal edition of DB2 – a mere 330MB.

The installation went pretty smooth but the first time I ran it I encountered a nagging missing DLL error thrown by the javaw. Weird because DB2 ships, runs and breaths its own JDK – IBM’s version 1.4.1. The error message recommended reinstalling the product, I did and things fared better – with the error going away. I did try to tell the installer to skip the IBM JDK installation but it ignored me. I do not care much because the system works.

DB2 is certainly a more mature product than SQL Server. It asks you for all sorts of information that has to do with tweaking its performance, from memory management limits to a variety of settings that have to do with automated optimization of the data stored on the server. What did bother me is that the wizards that are available in the DB2 Control Center application (parallel to Enterprise Manager in the SQL Server universe) – that are supposed to help you create databases, tables, etc. – do not seem to work too well.

The installation wizard ends with a ‘getting started’ window that encourages you to ‘create a database’. I tried that path and encountered a multitude of options that somehow – while using the defaults – failed to produce the promised database. What is also both neat and overwhelming is the fact that almost every operation that you try to make produces a result window that tells you if the operation succeeded. That’s all nice and well until you are returned an error. Each error reported is followed by a list of all the error codes that the error reports and it gets tedious when you look for the correct error.

I managed to create my database from a command line interface and then was able to use the wizard in the Control Center to create a table. Many things are really cool in DB2 – for example, you can ask a table what stored procedures or user defined functions use the table – an important feature when you are considering altering the table or modifying the stored procedure or UDF. Also neat it is the table creation wizard’s clean key definition – which in my opinion is superior to that of SQL Server.

Another thing I encountered was that as uncool a DBMS SQL Server is with Java, at least it produces readable error messages (most of the time…). DB2 provided me with this message when I violated a unique constraint on a column when I tried to insert a row:
SQLCODE: -803, SQLSTATE: 23505, SQLERRMC: 2;YZUKERMA.SUBMISSION
An A9 search on DB2 error codes lead me to the DB2 documentation page which is impressive in the amounts of information it provides. But all I want is a clear understanding what I did wrong, eh?

More impressions sooner than later…

Share
Categories
Web Development

New (to me) embedded web content editor from Mozilla

While browsing through the Firefox extension site I noticed cuneAform – which appears to be a browser-based editor that is embeddable in a web page. These are JavaScript components that you can add to a web page and that give users a word processor-like experience with a toolbar offering text manipulation functions (bold, italic, etc.) and more HTML-specific functions (styles, tables, image upload).

In the past, these editors sorta sucked because they were browser specific (I used soEditor which is IE specific and checked out BitFlux which was pretty hostile and did not work with IE). The best such editor I actually used is the Hardcore Internet editor which works really well and the company that produces it offers spectacular support for it. [Spectacular = bug resolution in less than 12 hours]

cuneAform is interesting in that it is both free and that it works with both browsers and is free. I did not check it with Safari or with Opera as this functionality normally is used in a client’s back end of a CMS application and hence the client can enforce the browser that is in use. In the past, that was an excuse to require IE to be used but allowing Firefox is just so better.

Share
Share