Saturday, March 21, 2009

Database connections in Java using JDBC and Netbeans IDE

I am fed up of people asking me how to make Database connections in Java . No one wants to go through the painfull part of studying themselves . All they want is the short-cut . So let me dedicate this particular posts to the topic of database connections in Java .

I have MySQL 5.0 installed on my Windows. In order to make a JDBC connection to MySQL database one needs to downlad the MySQL/J connector driver from here . I will also expect that you have Netbeans 6+ installed on your machine.

Extract the zip file to a folder, you’ll see file ‘mysql-connector-java-5.0.6-bin.jar’ which is the library file that we want. Just copy the file to the library folder, for example to “C:\Program Files\Java\jdk1.6.0_02\lib” also to the "C:\Program Files\Java\jdk1.6.0_02\jre\lib directory.

Next, create a new Java project on NetBeans named ‘TestMySQL’.

Now I’m going to write some code to connect to MySQL database. I have configured MySQL service on localhost.
I’m going to use Connection and DriverMapper Classes so I need to import libraries.
import java.sql.*;

Inorder to test my connections I build my project.

So everything seems to be fine till now.


To get some data, I need to execute query on the SQL Server and get the result back to me. First, I create stmt (Statement object) and execute query in SQL language. Then I store the result on ResultSet object and iterative show the result on the output window.

Insert some data to the created table using the code


Statement stmt = null;

stmt = con.createStatement();

String SQL = "INSERT INTO ZanduBaam (Name,Roll) VALUES ('Abhishek',40)";

int rowsEffected = stmt.executeUpdate(SQL);

System.out.println(rowsEffected + " rows effected");

Inorder to retrieve data from database , I need to execute query on the SQL Server and get the result back to me. First, I created stmt (Statement object) and execute query in SQL language. Then I store the result on ResultSet object and iterative show the result on the output window.

ResultSet rs = null;                                                                                                                                                                                                                                                // SQL query command                                                                                                                                                                                                                                           String SQL = "SELECT * FROM ZanduBaam";                                                                                                                                                                                               stmt = con.createStatement();                                                                                                                                                                                                                             rs = stmt.executeQuery(SQL);                                                                                                                                                                                                                     while ( {
System.out.println(rs.getString("Name") + " : " + rs.getString("Roll"));

Similarly you can do the required for updation and deletion .

Lots of time and sweat devoted to this post considering the fact that I have a test on Monday I should stop here.


Saturday, February 21, 2009

How to set up a USB Flash Drive from Windows to Windows in Virtual Box

Read the User Manual, available on Then,
Make sure the windows guest is dormant
Plug the Flash Drive into the Computer
Edit the VM Settings
Enable USB
Enable USB 2.0
Create a Filter
move the mouse over the add filter button and the USB devices will appear in the display box. This box is active. Select the one you want. If this is not obvious, then you can test this by removing the USB .
Start the VM and wait for Windows to do its plug and play magic.

This process was developed using a Windows Vista 32 bit guest and a Windows Vista 64 bit host, and a patched version of Virtual Vox 2.1.3

Dynamic Web Programming will turn the web-world upside down !

Sun Microsystems Research Lab is currently working on The Lively Kernel Project (Dynamic Web Programming Environment) which uses a dynamic language kernel and brings the same kind of simplicity, generality and flexibility to web programming that we have known in desktop programming for thirty years is likely to turn the world of web programming upside down. 
They have designed a new web programming environment called the Lively Kernel based on the JavaScript programming language, a desktop-style graphics graphics architecture (based on the Morphic graphics framework), and Ajax-style asynchronous networking support.
The platform places a special emphasis on treating web applications as true applications, as opposed to the document-oriented nature of most web applications today. It provides user interaction and direct manipulation capabilities that parallel or exceed the best desktop applications. A central feature of the system is support for collaborative applications, as well as the ability to run on a broad spectrum of target systems, ranging from desktop computers to mobile devices.

Google looking to replace Linux by Open Solaris as its data center.

"Google Inc. is experimenting with the open-source version of Sun Microsystems Inc.'s Solaris operating system as a possible long-term prelude to replacing its massive global network of Linux servers.With dozens of data centers worldwide estimated to house hundreds of thousands of Intel servers supporting its flagship search engine, a Google move to OpenSolaris would be another of several recent votes of confidence for the platform."

Source :

Monday, February 16, 2009

Useful resources for starting out with AJAX development

The field of AJAX is pretty messy today, much as any web developer will say. The moment you come up with a cool new idea for a Web-based Application, you simply hit a roadblock when you wonder, "Where do I begin?". This is the same with experienced web developers AND newbies. This is because there is no straight-forward, structured way of developing "web programs" unlike their counterparts in the Desktop applications environment.
Here are some of the resources that could save you.
Check out:
ZK -- Server side, very little programming required.

Another notable feature of AJAX-based applications, or the so-called Web 2.0 apps, is the rich and responsive User Interface they provide. Coding them from scratch is simply a waste of time and "re-inventing the wheel" unless you really have a good reason to do it. So here are some useful Javascript graphic libraries that you can use which have ready-made rich and responsive components:

Hope this helps.Please reply if you liked it.

Sunday, February 15, 2009

Campaigning ...

Today morning I went to campaign for my friends Ravi and Vishal in Hall - 9 . The students union elections are going to be held on Wednesday and my close friend and room-mate Ravi Shankar Prasad is a candidate for the AGS (Cultural) . This is the second occasion when I have been a part of a campaign , few days back we did it at Hall - 7 , the ladies hostels as we say and the response was very pleasing . The propaganda's discussed very mature and serious and appropriate to the present scenario where the placements are facing a tough time thanks to the recession . Things like student accomodation with increase in student strength were also discussed . Some MCA girls have to accomodate outside the college campus which is utter shame in the name of the institute.
Coupon -System and Night canteen were among the other things promised .
Hope we come to power and really make some difference .

Saturday, February 14, 2009

Code JavaFX Contest

Code JavaFX Contest

Sun Microsystems announced the Code JavaFX Contest 2009 contest. Students and developers across India can participate in this contest. This contest is aimed to generate enthusiasm for the JavaFX technology and to encourage developers to develop and contribute sample applications or games that demonstrate use of JavaFX in creating rich internet applications. Prizes will be awarded to those who submit the best entries as determined by the judges in accordance with these Official Rules.