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)

Wednesday, December 17, 2008

JavaFX SDK 1.0 Released

Develop Rich Internet Applications With the JavaFX Platform

Laptop desktop mobile tv screens


The JavaFX platform gives unparalleled freedom and flexibility to create Rich Internet Applications (RIAs) and content across multiple screens, including mobile phones, desktops, televisions, and other consumer devices.It combines the best capabilities of the Java platform with comprehensive, immersive media functionality into an intuitive and comprehensive, one-stop development environment.

The JavaFX platform empowers content developers by enabling them to focus on creativity instead of coding. It enables developers to create game-changing applications and engaging content with maximum market penetration opportunities.

JavaFX 1.0 marks the first step in Sun's strategy to enable rich immersive media and content across all screens.

Why the JavaFX Platform?

RIA imagesDevelopers are seeking the most efficient way of creating RIAs across all screens. They need to build high-fidelity GUI's that operate seamlessly on multiple Web browsers, operating systems and devices, without having to port or rewrite their applications for each screen. To meet this goal, developers need to work efficiently with team members such as graphics designers and media authors to exchange audio, video and other rich media assets

The JavaFX 1.0 platform introduces an essential set of tools and technologies that enable developers and designers to collaborate, create, and deploy RIAs to browsers and desktops. In addition, mobile application developers can use the JavaFX 1.0 Mobile Emulator Beta Release to preview development of mobile RIAs using the JavaFX platform.

Key features of the JavaFX 1.0 platform include:

  • One-stop shop RIA platform for all screens: Build engaging visual experiences across desktop, browser and mobile with a unified development and deployment model.

  • Broadest market reach: Distribute RIAs easily across billions of devices with the power of Java.

  • Designer-developer workflow: Dramatically shorten your production cycle for design and development.

  • Powerful runtime: Leverage the extreme ubiquity, power, performance and security of the Java runtime.

  • Break free from the browser: Drag-and drop a JavaFX application from the browser to deploy to the desktop.

  • Java technology compatibility: Preserve your investment by enabling the use of any Java library within a JavaFX application.

xVM VirtualBox 2.1 released

Just a heads up that xVM VirtualBox 2.1 has been released today December 17.  http://www.sun.com/virtualbox .
Some amazing milestones for xVM Virtualbox 
include: 
Over 8 million downloads worldwide, 2.5 million registrations and 25,000 
downloads a day 
Just some of the features that are available in xVM VirtualBox 2.1 include: 
- New Accelerated 3D Graphics 
- Improved Network Performance 
- Storage Support (built-in iSCSI support to connect to storage systems 
ie Amber Road) 

xVM VirtualBox 2.1 software offers improved support for: 

- Mac OS X on Intel's Virtualization Technology (VT-x) 
- VMware's and Microsoft's Virtualization Formats 
- Intel® Core^TM i7 processor 
- 64-bit guest OS on 32-bit host platforms 

And of course you'll be able to download xVM VirtualBox 2.1 at: 
http://www.sun.com/software/products/virtualbox/get.jsp 

Sunday, December 14, 2008

"OpenSolaris is the state of the art, cutting edge operating system that provides a rich, coherent platform for building and running applications.

OpenSolaris offers free, built-in features that help you build, debug and deploy new applications faster. It's is an operating system (OS), an open source project licensed under CDDL, and a community.

The project's goals are innovation, collaboration, and the extension of OpenSolaris technology." (www.opensolaris.com)

They just released the 2008.11 version, with some new cool tools like TimeSlider and much more hardware compatibility.

New features in OpenSolaris 2008.11

Download !

Kaffeine Wars


What's Brewin' ?


Kaffeine Wars ~ Java Programming Competition on Linux Platform.

Java is the preferred Programming Language for all web-based applications today. Its Importance in Software Industry is tremendous. As of May 2007, in compliance with the specifications of the Java Community Process, Sun made available most of their Java technologies as free software under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java and GNU Classpath.

Sun Club in collaboration with GLUG , NIT Durgapur give the participants a rare chance to test their coding skills in Java. The platform of programming will be Linux . Programming contest in Java is a rarity in the various competitions across India. Hence it's a superb chance for the technocrats to have a go at the Steaming Hot Kaffeine.

And yes the Stronger it is, the Better it proves to be!!!

RULES AND REGULATIONS

Each team should consist of a maximum of two participants.
A number of teams will be shortlisted for the Final Round from the Elimination Round.

LAYOUT

Kaffeine Wars is an on-the-spot Java Programming competition. The competition will be held in two stages

1. Prelims
2. Mains

both of which will be held onspot at NIT Durgapur during MUKTI ‘09

Round 1

This will be an elimination round. It will contain objective questions. The duration will be declared on the day of the contest at the venue.

Round 2

Only the selected candidates from Round 1 will be allowed to attend Round 2. The number and nature of the problems and the evaluation criteria will be revealed at the venue, depending on the problems.Nature of problem will be something similar to implementation of a Desktop Application .

The participants will be allowed to take in any standard Core Java book .

Link : http://mukti09.in/

SKILLS SET REQUIRED

Core Java Coding skills.

SOFTWARES




Saturday, December 6, 2008

All about GlassFish


The use of GlassFish application server is growing, and having a reference card for day-to-day jobs is inevitable. Looking for a sample command to perform a specific job can take time but by using this refcard, you wont need to look for any commands or lose time searching in countless pages of manuals and administration references. This refcard covers administration, security, and performance management topics.

Contents of RefCardz:


  • About Glassfish

  • Installing GlassFish

  • GlassFish Domains Profile

  • Common Administration Tasks

  • Clustering and Load Balancing

  • Hot tips and more...

Download the RefCardz here.

NITD OSUM community is now 100+

I am immensely pleased to announce that NITD OSUM community is now 100+ . It is a great achievement considering the fact that our institute is only the 3rd in India to have done that after NIT, Surathkal and JIIT, Haryana . To an extent the members enjoyed the whole process and also actively participated in the community activities showing great enthusiasm while at the same time some of them had a hard time with their inbox full of osum activity notifications which I think should be modified a bit as it follows every member a lot.

But after all this the bottom line is the fact that NITD has been awarded a pizza treat from Gary Serda , the creator of OSUM and soon I will be looking forward to execute this tough task considering the fact that we don't find good pizza's in Durgapur !

Let me share with you what he said :


However I would also like to say that this group is something more than a pizza party as it provides the students under the SAI program to enjoy some staggering benefits and also keep them upadated about sun's cool open source technologies .

You can join it here by signing up at http://osum.sun.com/ and then joining the group http://osum.sun.com/group/nitdurgaprosum

I assure you that u'll be at profit.