Connect to MS SQL Server using JDBC

The following example shows a java class that can be used to verify if you connection to MS SQL Server using JDBC is working properly. The following code establishes a connection to MS SQL server and then executes a query to print system tables. You need to get Microsoft’s JDBC drivers or jTDS JDBC drivers.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
 
public class ConnectMSSQLServer
{
   public void dbConnect(String db_connect_string,
            String db_userid,
            String db_password)
   {
      try {
         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
         Connection conn = DriverManager.getConnection(db_connect_string,
                  db_userid, db_password);
         System.out.println("connected");
         Statement statement = conn.createStatement();
         String queryString = "select * from sysobjects where type='u'";
         ResultSet rs = statement.executeQuery(queryString);
         while (rs.next()) {
            System.out.println(rs.getString(1));
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
 
   public static void main(String[] args)
   {
      ConnectMSSQLServer connServer = new ConnectMSSQLServer();
      connServer.dbConnect("jdbc:sqlserver://<hostname>", "<user>",
               "<password>");
   }
}

Change <hostname>, <user> and <password> to the correct values. Also, if you use the jTDS drivers, the driver class should be set to net.sourceforge.jtds.jdbc.Driver.

Say Hello to HemingwayEx 1.0

After about 4 months of inactivity little activity, I finally sat down sometime back and updated HemingwayEx. Added some much needed new features and squashed some old bugs. Again, a lot of help came from many others who have liked this forum and were nice enough to report bugs and give ideas of what more can be done with the theme.

Anyways, with this relase, HemingwayEx has made a major jump. The theme is now Widgetized. Users can now go to the options page and set whether they want to use the old blocks system or use widgets for sidebars. I have also added a font size changer and added comment numbering.

Going forward, I am planning on making the theme more customizable and adding internationalization support. Also, will work on adding more user styles.

Here are the pseudo release notes / changelog:

Version: 1.0
Release date: Jul 14, 2007
Release Notes: I have fixed a few more bugs. Also added some major features into the theme.

Added Features

  • Widgetized the theme. User can switch between using Hemingway Blocks System or Widgetized Sidebars.
  • Added a font size changer. Now viewers can increase / decrease the size of font by clicking on a few links just below the search form. Credit goes to this simple and easy tutorial.
  • Numbered comments, that look (IMHO) cool.
  • Added an Asides Widget to be used when theme is being used in widgetized mode. The functionality is the same as the Asides block previously added to HemingwayEx.
  • Added a new block WordSpew, thanks to Darwin.

Bug Fixes

  • Simple CSS fixes to style.css
  • Added more properties to white.css
  • Removed all PHP short tags. I think this time I got ’em all.
  • Fixed bugs pointed out by Darwin

Tested on : WordPress 2.1 and WordPress 2.2.1 with IE6, IE7 and Firefox

HemingwayEx 0.95 beta

I have updated HemingwayEx wordpress theme by adding some simple new features. I also made some bug fixes. The best thing about this update is that now users will see a notification of a new version on the HemingwayEx Option page. I really hope that this works. I am not much of a PHP coder… just hacked up what I could by reading Peter Harkins’s code for the wordpress plug-in Sociable.

I also fixed some more CSS issues with the white.css stylesheet. The worst part about styling a theme is making it compatible with different browsers. I must make my displeasure with IE’s handling of CSS very clear here. I have done what I can for now and will keep fixing things as I learn more.

You can download the latest version, 0.95 beta from HemingwayEx homepage.

If you are UPGRADING, you will need to reset/uninstall the previous version of HemingwayEx first as I have moved the blocks around. If you don’t you might find the display mixed up. Here are the steps you should follow:

  1. Goto HemingwayEx Options page and note down you settings.
  2. Now upload the new files for HemingwayEx theme.
  3. Click reset button right at the bottom of the HemingwayEx options page.
  4. Refresh the HemingwayEx Options page and set the options to what they were before.

Mt Rushmore Trip

sucked…

The weather wasn’t all that great… it was really hot during the day and it rained the night when we camped… couldn’t go trekking cause everyone wasn’t ready. Mt Rushmore isn’t that big of a deal… many might not agree with that statement, but I was really disappointed after sitting in a car for 15 hours. Ohh… and the car… it was another experience in itself… Six people with a lot of luggage were packed tightly into a Mercury Mountaineer… On the way back we got a ticket as well…

I guess just because my experience wasn’t all that great (because of the things mentioned above… and many that I can’t mention here), I feel that the weekend was a waste… South Dakota is a nice place… it makes sense passing though SD or staying there over night when you are out on a long road trip. Making a trip to SD, doesn’t make any sense.

Kabhi Kabhi

Loved these lyrics… have heard this song many times and few days back was the first time I actually listened to the words… I tend to just enjoy the music and not listen to the lyrics. Beautifully expressed emotions… 🙂

Kabhi kabhi mere dil main khayal aata hain
Ki zindagi teri zulfon ki narm chhaon main guzarne pati
to shadab ho bhi sakti thi.

Yeh ranj-o-gham ki siyahi jo dil pe chhayi hain
Teri nazar ki shuaon main kho bhi sakti thi.

Magar yeh ho na saka aur ab ye aalam hain
Ki tu nahin, tera gham teri justjoo bhi nahin.

Guzar rahi hain kuchh iss tarah zindagi jaise,
isse kisi ke sahare ki aarzoo bhi nahin.

Na koi raah, na manzil, na roshni ka suraag
Bhatak rahin hai andheron main zindagi meri.

Inhi andheron main reh jaoonga kabhi kho kar
Main janta hoon meri hum-nafas, magar yoonhi
Kabhi kabhi mere dil main khayal aata hai.

Shadab=fresh,delightful
Ranj=distress,grief
Justjoo=desire
Nafas=breath
Shuaon=light

(source for lyrics)

Update: These lyrics are a simpler version of a sher by Sahir Ludhianavi.

Mad World – Gary Jules

This song is by Gary Jules that plays right the end of Donnie Darko. Please… please… do yourself a favor and listen to this song… and also, try to watch this movie…

All around me are familiar faces
Worn out places, Worn out faces
Bright and early for the daily races
Going nowhere, Going nowhere
Their tears are filling up their glasses
No expression, No expression
Hide my head I want to drown my sorrows
No tomorrow, No tomorrow
 
And I find it kind of funny, I find it kind of sad
These dreams in which I’m dying, Are the best I’ve ever had
I find it hard to tell you, I find it hard to take
When people run in circles its a very very…
Mad World, Mad World

Children waiting for the day they feel good
Happy Birthday, Happy Birthday
And they feel the way that every child should
Sit and listen, Sit and listen
Went to school and I was very nervous
No one knew me, No one knew me
Hello teacher tell me what’s my lesson
Look right through me, Look right through me
 
And I find it kind of funny, I find it kind of sad
The dreams in which I’m dying, Are the best I’ve ever had
I find it hard to tell you, I find it hard to take
When people run in circles it’s a very very…
Mad World, Mad World

Enlargen your world…

Mad World…