Skip to main content


Showing posts from September, 2008

How to auto-fill lots of columns or cells with the same value in Excel

I had a spreadsheet recently (actually a CSV file which contained numerous columns of data. The values in the cells were either blank (empty) or the letter 'Y'. I needed to change all the blanks to 'N'.

Find and replace didn't work as you can't specify blank as a matching character (at least I couldn't find out how, please comment if you know!) and I didn't have the energy or time to manually update each cell. After some research I found that the answer was the 'Goto -> Special' options hidden within the 'Edit' menu.

Here's how to do it...Select the columns and/or cells that you want to perform the special find within (hold down CTRL as you click the column headers or individual cells.
Click the 'Edit' menu and select 'Go To...':

Then click the 'Special...' button:

Then click the 'Blanks' option and click 'OK':

Any cells within your selection that contain blanks will now be selected leaving th…

How to run individual JUnit unit test methods within Eclipse

Eclipse supports JUnit out of the box, and even has a handy keyboard shortcut for running all the test methods within a JUnit test class: CTRL-F11. You can also right-click within the unit test class, choose 'Run As' then 'JUnit Test'.

But what if you want to run just one of the many test methods with a particular test class? IntelliJ's IDEA has this option (you just right-click on the method name and run it) but Eclipse doesn't offer that feature.

One solution is to run all the tests within the test class (as described above) and then click on the particular test in the left-hand JUnit results window, right-click on the test and choose 'Run':

The other is to open the "Outline" view, and then right-click on appropriate unit test method, choose 'Run As' then 'JUnit Test':

That means that you don't have to run all the tests within a test class just to be able to run one of them. Now isn't that easier?

Technorati Tags: ,

Using ampersands (&) without variable substitution in Oracle either direct or with SQL*Plus

Oracle uses the ampersand (&) symbol within a string to indicate a substitution variable. But what if you want to use an ampersand as part of a regular string such as 'Bob & Sons'?

There are two solutions that I know of and which one you use depends on the context in which you are running your SQL:
Dealing with the ampersand on an SQL levelTo turn off interpreting the ampersand as a substitution variable it must be at the end of a string:insert into companies values ('Bob &' || ' Sons');Dealing with the ampersand when using SQL*PlusTo disable Oracle's variable substitution and therefore return & to the pool of standard characters you need to tell SQL*Plus to disable it:set define offAdd that to the top of your Oracle SQL script or type it manually at the SQL*Plus prompt.

These tips plus many more can be found within the rather useful The Oracle (tm) Users' Co-Operative FAQ.

Technorati Tags: , , ,

Hibernate HQL problems with database views and deleted rows within the same transaction

I found an interesting Hibernate view-related issue yesterday when deleting some data from a table within a single transaction.

Let me set the scene a little - we have a People table which has one row per person. We have a FamilyTree database view which displays family trees using the People table as one of it's sources (it's quite a complex view with functions and the like but you get the picture).

I was writing some unit tests around the area of deleting people. I used the view to get a list of people, deleted a person from the People table and then used the view to ensure that the person was gone. All of this was done with Hibernate-annotated domain objects and some JPA-based DaoSupport style classes - the standard Spring/Hibernate way.

What I found was that when we were within a single transaction (i.e. within a unit test or within a web controller using the OpenSessionInView) and we delete from the table, the 'deleted row' is still visible and therefore incorrect.…