Peter Heide

Ranch Hand
+ Follow
since Nov 04, 2006
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 Peter Heide

Thank you Tim for you deep analyses.

It seems that the vendor driver support for Java 7 and JDBC 4.1 is not yet really good.

We tried MS Access Database, but got the same error.

Then we decided to evaluate the Apache Derby Database, which I think is Open Source and was used in the Java 7 New Features Cookbook.

From the Oracle web pages where we downloaded the Java 7 JDK, there are already JDK 7 Demos and Samples available. They are having example code for the Derby database and the Derby download link.

They open a DB, creating a Table, filling it using SQL statements and drop the table again. We included the following code and it worked:

I would like to make a select statement on an MS 2002 Excel Table using JDK 7 under Windows XP 32 Bit.

I have an Excel file named Test.xls with a Sheet named Table. The Sheet is our Table and has two columns ID and Name:

In Windows Settings I created a data source named EXCEL_TEST which is connected to the Excel file.

The following code works fine under Java 6:

The output is the content of the Excel file:

Now I am using Java 7 JDK, with the following code. I am trying to use the new JDBC features described in the book Java 7 New Features Cookbook from Richard M. Reese and Jennifer L. Reese in chapter Using the RowSetFactory:

It gives me the following error:

I think that the JdbcRowSetImpl class is not a part of the JDK 7. It could be in a JDBC Driver 4.1 from Microsoft. According to my knowledge there is no such driver from Microsoft realesed so far.

Any Ideas?

Add this to the main method:

The output ist:

Vehecle Breaking....

The reference is of type Vehicle and the object is of type Prius. It takes the Vehicle.breaking() and not the Toyota.breaking() because both methods are static methods and they are not overridden.
Thank you for all your help guys! Of course you are right, the simplest code ist the best for the given problem.
But I wanted to figure out how to solve it with an regular expression. Thank you Ireneusz Kordal for your correct regular expression!

The following code :

Delivers the following answer I needed:

This program delivers false when a String contains the String "TEST" and true otherwise (It is forbidden to have the Substring "TEST" in a String)
OK! String "TEST" delivers false
OK! String "TEST TEST" delivers false
OK! String "123 TEST 456" delivers false
OK! String "Peter" delivers true

14 years ago
The following regular expression matches for all Strings that contains word TEST, not matter if in the beginning or in the end:


How would the regular expression look like that matches for all Strings that do not contain the word TEST?

For testing I am using the following code:

I know that it is possible to program this with the indexOf method of the String class, but I need to implement this using regular expressions.
14 years ago
Thank you Ankit Garg for your answer, I think you are absolutely right!
I am wondering if the Strings in the string pool are getting eligible for garbage collection or are living there until the program ends.

Given the following, is the string s one or two times time eligible?

The Problem is:

This method returns null according to javadoc when the Workbench or Operating System does not give you a console.

I got an exception too using Eclipse and Windows. It worked fine using a MS DOS prompt.

You can at least add to your program to something like this:

I hope someone can find out how we get a valid console within Eclipse.
Strings are immutable so the two string objects on the heap dines and alok are not eligible for garbace collection until the program ends.

The two references disp and show live on the stack and will be removed when the main method is done.
Usually two different objects would not be equal when their hash code is different.

But the equal method is overwritten in you code. Here two objects of type TestTwelve are equal exacly when their x member variable are equal.

You gave all of your x member variables the same value which is 3.

Therefore your overloaded equals method gave true as result.
Thank you Richie, your proposal works fine using the OR (|) is the regular expression:

Sometimes when you have a problem it looks quite complicated. When you see the solution it looks so easy.
16 years ago
I need to write a regular expression according to the following rules:

String starts with an "A"
String continues with 4 to 6 uppercase letters "A-Z" or digits "0-9"


String starts with an uppercase letter from "B-Z"
String continues with 6 digits "0-9"

The following code uses two regular expressions, one for the first case and one for the second case.

It works, but it would be better and shorter to put everything into one single regular expression. I believe it is possible because regular expressions are very powerful, but I do not know how...

Has anyone an idea how to do this?

[ April 14, 2008: Message edited by: Peter Heide ]
16 years ago
You solved the problem and also your advice to improve my code worked. Thank you very much Anubhav and Jim!
16 years ago
Regular Expressions can be used to validate if a String is in a valid format.

The following code checks if a string is valid using the following two rules

  • Starts with a letter from A to Z
  • Afterwards exactly 6 digits

  • Examples: A123456 is correct, A12345 is incorrect, AA is incorect

    The Java code is as follows:

    Result Output:

    ID A123456 is true
    ID A1 is false
    ID AA is false

    The problem is that a new rule comes into play:

    An ID is not valid when it starts with A33

    How can I code the first two rules and the new one together in one regular expression?
    16 years ago
    Hi Naveen,

    your class name is testconstructor.

    A constructor must have the same name and no return type, e.g.:

    You wrote a method that had the same name as the class, but no constructor. It is no constructur because it has a return type, even when the return type is void. This was legal, but the method was not called as you constructed an object of the class:

    So x and y are still 0.

    Hope it helps,