6
May/10
0

Reading a TimeStamp Value from a MySQL Database in your Java Program

So, you’ve written your database table to have a Timestamp column in it. Often this can be used to log when an entry is created or updated. This post will detail a couple of things that may be useful in doing more than just having it logged.

Java provides a java.sql.Timestamp class that can be used to read and alter timestamp values.

So if your database column is called signup_time, it can be read out as follows

import java.sql.Timestamp;

        Statement st = con.createStatement() ;
        ResultSet rs = st.executeQuery(  “SELECT * FROM subscribers”  ) ;
        StandardSubscriptionUser users[] = new StandardSubscriptionUser[ count ] ;
        rs.beforeFirst() ;
        while( rs.next() && count>0 )
        {

               signupTime = rs.getTimestamp("signup_time") ;

        }

The Timestamp class is a subclass of java.util.Date. However there is not quite a match between how java.util.Date and java.sql.Timetamp store the time. This means that a Timestamp object should not be used where Date objects are required in functions. As the API says “The inheritance relationship between Timestamp and java.util.Date really denotes implementation inheritance, and not type inheritance.”

However it does mean that the standard Date API methods can be used to do things with the Timestamp object, meaning there is a set of standard methods to manipulate and access the values with.

30
Apr/10
1

Selecting MySQL Rows with Timestamp Column in a date range from a Java Program

You have a MySQL database table with a Timestamp column, and you need to select a range of dates in which you need to select entries from.

As ever a SELECT statement with a WHERE clause is needed. The following will give you a range of dates from the first to the last. Note that without times specified it is the start of each day. So although 2008-08-31 is specifed no entries on that date will actually be included in the returned results.

String sqlWhereDate =
                " order_placed BETWEEN \”1995-05-01\” AND \”2008-08-31\” ” ;

String sql = “SELECT * FROM orders WHERE ” + sqlWhereDate ;

Tagged as:
4
Apr/10
1

Netbeans Editor Code Folds

Some times its handy to be able to hide sections of code in the Netbeans editor window.

// <editor-fold desc="This section of the code deals with the item.">
 Your code goes here...
// </editor-fold>

These are just the basics. More information is available from the Netbeans page.

31
Mar/10
0

WordPress on the frontpage – displays category content, but not title

So here’s an interesting one. Often I have sites with a page where there is a subcategory with a few of the latest entries fully featured on the front page. The following code, when I tried it, did not display the title for the subcategory entries. Instead of the subcategory post title I got the main page title.

<?php
 $newsposts = get_posts('numberposts=2&category=4');
 foreach($newsposts as $newspost_single) :
 setup_postdata($newspost_single);
?>
 <div>
 <h3><?php the_title(); ?></h3>
 <?php the_content(); ?>
 <hr>

 </div>
<?php endforeach; ?>

The fix? To change the $newspost_single variable to $post. Not sure why this is the fix, and I should see if it counts as a bug, but it worked for me.

Filed under: Wordpress
30
Mar/10
2

jQuery / Java / Autocomplete

If you haven’t heard of jQuery, its a Javascript library that allows you to implement AJAX functionality in your web pages. You can find out more about it from the jQuery website.

My first attempt with jQuery involved using an autocomplete  plugin provided by Pengoworks. Autocomplete is where you start typing in a few letters and the text box will come up with some suggestions. There was a tutorial for this present on the jquery autocomplete page, but it didn’t quite meet my needs, and maybe it doesn’t meet yours.

There are two ways in which to use the auto complete functionality. If there are a few options (ie upto 50) the list of suggestions can be embedded in the web page itself, but if there are many options (1000s) the suggestions need to come back from a server. It was this second process that the tutorial did not cover, and hence the reason for providing a step by step guide to doing it here.

In partcular, I’m working from Java in Netbeans 6.8.

29
Jan/10
0

Adobe Premiere 8.0 on Windows 7 64-bit Problems

I installed Adobe Premiere Elements 8.0 on Windows 7 64-bit. The purchase I’d made was of the boxed version for the UK. Installation went fine, but on trying to run other issues ran up.

First up was when trying to create a new project the program would hang. The project files would get created and but it was a case of putting up the Ctrl-Alt-Del Task Manager and stopping the process. Most intriguing of all was a message saying that ‘Can not open Adobe Premiere Pro projects in Adobe Premiere Elements’.

The Fix: Reinstall the software, but get the download from the online Adobe store. Before uninstalling the software choose ‘Deactivate’ from the program menu if you have already activated the software. This will save you licencing issues in the long run. You can download the trial version from the Adobe website but then at install time when prompted for a Serial Number enter the one on the back of the box.

Downloading the trial version had its own issue – the link to the trial gave me a Error 302 Resource Moved error. Luckily the URL had embedded the URLs for the two files needed – the .7z file and the .exe installer, so grabbing them individually became no issue.

A second fix for me was to make sure I had the latest graphics drivers for my card, particularly NVIDIA systems. At time of writing I had to go to a beta driver rather than an official one to get something that worked, so this may be worth considering.

24
Oct/09
1

Windows 7 is Windows Heaven

As you have probably read about the new Windows release is absolutely the best Windows upgrade ever. It feels light and responsive and the laptop battery gets an extra half hour of juice (through normal usage if not any formally quantified test).

You can order Windows 7 Here

Don’t forget also that Ubuntu also has a new release coming up! Which is free ;-)

Filed under: Windows
30
Aug/09
0

MyEclipse Hibernate/RESTful web services MethodNotFound Error

So there I was happily setting up my code when I get an error. This was using Hibernate 3.2 and JAX-RS 1.0.2 web services for running some web services to add users to a database on MyEclipse 7.5.

What was the issue? When I try accessing the project if the data is verified ok and is to be added to the database the following Exception cropped up:
java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter

A bit more investigation yields the problem to be asm.jar issues. v1.5.3 is bundled with the Hibernate 3.2 package and a newer sounding v3.1 with the JAX-RS libraries bundled with MyEclipse.

What could be done? Well the reason the asm.jar file is needed in Hibernate is because of another JAR file cglib. This is called a dependancy and we can stop the problem by replacing this with a non-dependant version and then taking away the old asm.jar file.

  1. Download the cglib nodep JAR file from http://cglib.sourceforge.net/. Place the JAR file in a repository somewhere.
  2. Open MyEclipse -> Preferences -> Project Capabilities -> Hibernate.
  3. Select Hibernate 3.2 from the Tabs
  4. Switch the view from the drop down menu to view the JAR files for the Core Library.
  5. Click Add JAR/ZIP Button and select the downloaded cglib-nodep-x.x.jar downloaded in Step 1.
  6. In the list locate asm.jar and remove.
  7. In the list locate the cglib-x.x.jar file and remove.
  8. At this point your list screen will probably look like the screen below. Click OK.
  9. Stop the server and undeploy the applicaton
  10. Restart the server and redeploy the application

myeclipse-hibernate library changes screen grab

Filed under: MyEclipse
28
Aug/09
0

Adding A MyEclipse Project To Subversion Repository

MyEclipse can work with Subversion, through the Subversive plug-in. This can be added as described here.

It wasn’t immediately obvious how to add a project to a Subversion Repository – in Netbeans you can right click on the project, but in MyEclipse you need to change Perspective to the ‘SVN Repository Exploring’ Perspective.  Right click in the SVN Repositories window and add a new one (this is one you will have already setup).

You can create folders within your repository (Right Click->New->Folder)  - I advise doing this for each project you are using. Then right click on the folder being used, choose Import and then choose the root directory of the project you wish to add to the repository. You may add the whole workspace to this.

Books On Subversion

10
Aug/09
0

Removing And Reinstalling MySQL on Windows

I had to reinstall MySQL 5.1 on my Windows machine, and ran into an issue – the service was still installed even though the program was removed.

To get rid of the service go to  the registry (type regedit in the Program search menu).

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services

find MySQL, delete, and restart Windows.

Tagged as: