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 (rs.next()) {
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.

Bbye.

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 http://www.virtualbox.org/wiki/Downloads. 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 : http://www.computerworld.com

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:
 Prototype
 Dojo
 
Mootools
 
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.

Kaffeine Wars - A tremendous success !!!

It was a Friday morning and I realized that my event (Kaffeine Wars) was given the slot on the same day and was supposed to commence from 1:30pm . I took me about one and half hours to prepare the questions for the preliminary round (Round 1). To my surprise there was no delay at all and Round 1 started on time thanks to the support and effort shown by the volunteers of Sun Club .
Fifty one students from within and outside the college participated with great enthusiasm and from these 26 teams 11 teams were shortlisted for Round 2 which was the onspot coding round.
Round 2 started on schedule from 00:30 am midnight and finished at 5:00 am in the morning. The problem statement was implementation of an extensive lightweight word processor using the RTFEditor Toolkit for editing the Rich-Text-Format files having all the features that a typical word processor has.
Again to my surprise the response was amazing as I never expected such good results in a short span of four hours with no support except Sun Java API docs.
Two teams emerged with some professional stuff performance and were awarded as the Kaffeine Wars 2009 Champs .
The team coming second was a talented pair of boys from NIT Jamshedpur and the Champions were from our very own NIT Durgapur , second year students - Aritra and Shankha .
Check out the pics and the snapshots as they speak a lot about the events' success !












Seminar on Sun Technologies at NIT Durgapur

After a whole lot of efforts and arrangements, the seminar by Mr. Tirthankar Das on open solaris and Sunspots was conducted in our auditorium (D.M Sen Memorial). The talk was sceduled at 10:00AM on the second day of Mukti 09' .The hall that has a capacity of 150 was full of patient audience.It went off pretty well and i have some cool feedbacks too...!!....I think some students got really interested in DTrace and other data security features like snapshots of Open solaris .
I guess the most interesting feature was Time Slider.



I will try and give them some cool tech talks on these individual topics in the months to come..!

Here are some pics of the events...sure they'll be interesting


Friday, January 30, 2009

NetBeans Tech-Talk / Demo at NIT Durgapur

Finally I had my first talk at NITDgp !!!
Response was awesum!! More than 60 (to be precise 67) people turned up so LG-C3 being the biggest classroom at the Computer Science Dept was almost full.Inspite of two other events going on paralelly in the college the turnout was highly unexpected.The reason of the huge turnout was I feel the very Sun Brand !


In the first part of my Demo I covered many topics related to Netbeans Intelligent Text Editor and showed them techniques like Code-Insertion , Code-Refactoring ,Using Javadoc , Live Code Parser and error checker ,
Local History , Code completion , Instant renaming , Compile on Save,and lots of other cool stuffs.
I explained them how to use the Profiler and the Debugger.
I explained them the use of Version Control and automated testing (Unit Testing) .


This was followed by a basic demonstration on the Swing Gui Builder and with functionalities like Automatic feedback , Quick Component Insertion , Anchoring , Alignment .


After this I expained the basic features of event handling and demonstrated it with a small application built using the Swing Builder .


As people asked for more meat so I continued out of my plan to demonstrate them easy Data Binding using MySQL database , JTable and Java Persistence API showing them how to createa CRUD application in 5 mins!


On public demand I also showed them how to import an existing PHP-MySQL project in Netbeans and showed them advantage of using WEB 2.0 frameworks like JMaki and Dojo directly into the existing PHP project.


I gave them an introduction to Visual Web Java Server Faces by demonstrating them how to populated a Woodstock Table from a MYSQL database using simple drag-drop.

Many obvious questions like why Netbeans over Eclipse which I think I answered satisfactorily. Many people came to me afterwards asking more details about multibooting Solaris and more about Web 2.0 and AJAX.
I was on the top of the world when people actually clapped at the end of the talk.
All in all a nice experience. Waiting to have many more sessions like that!! .

Feedbacks :
phuloria: absolutely awesome
for the first time i found it fun
Amit Phuloria , 3rd Year CSE
Pics:




My First Experience with Virtual Box

I had already been using opensolaris on my laptop within a dual boot system but sadly few days back my laptop got spoilt that too the system board . I got a laptop from my
sister's friend on a temporary basis . I was obviously not allowed to install a new OS on to it. It was when the idea came to my mind about installing opensolaris on VirtualBox . The reason why I chose virtualBox was because I had earlier used Vmware and my experience was not good at all.
As now I have successfully installed opensolaris on virtualBox and everything is working excellent I want to share my experience with you all .
Infact with VBox you won't find any difference between a metal installed opensolaris and virtually installed opensolaris .

INSTALLING VIRTUALBOX
You can get binaries for all platforms from the site below.The site also contains a user manual which is more than sufficient to get you through the initial installation procedure.

http://www.virtualbox.org/wiki/Downloads


Starting the OpenSolaris virtual machine installed in VirtualBox











OpenSolaris desktop (1280 * 600 resolution)

(One of the main nuances I faced in installing Ubuntu as a guest in VirtuaBox is that I found it very difficult to configure the screen resolution. I spent so much time in something which should have been a easy task. I even wrote a blog entry about increasing the screen resolution in Ubuntu. But in OpenSolaris, I got the maximum resolution just by installing the guest additions.)



And access to the screen resolution setting cannot be this simpler. Just right click anywhere in your desktop and you are there.



And here is the actual screen resolution user interface


Some Applications pre-installed in OpenSolaris



Package Manager

(One good thing about OpenSolaris is that it comes preinstalled with most apps needed for a Java developer)