embed

Image

This is a sample doc for embeding into the blog.

Liability of the members of a Company is limited to the extent of value of shares held by them. If certain shares are partly paid & the Company gotraines into liquidation the members are liable only to the extent of the unpaid amount.

Liability of members may also be limited to the extent of the guarantee given by them.

There may also be Companies with unlimited liability.

Servlet with MySQL database connection

All the explicit commands I have used are for linux system, however everything we have used here is cross-platform so you will have no problems.Just take care of the paths while compiling.

The instructions are for apache-tomcat 5.5 If you  don’t have it already, get it from http://tinyurl.com/get-apache-tomcat5 . You will need JDK and MySQL server. Also, to make a connection to the MySql server, you will need JDBC drivers for MySQL, get it from http://dev.mysql.com/downloads/connector/j/5.1.html . Extract the archive . Inside it you will find a jar file called mysql-connector-java-5.1.10-bin.jar , this contains the jdbc drivers we need.We are good to go.

These are the sql statements for creating the database and populating it:

Here are the SQL statements for the database:

create database books;

use books;

create table books_details(id INT(11) AUTO_INCREMENT, book_name varchar(100) NOT NULL, author varchar(100) NOT NULL,PRIMARY KEY(id));

insert into books_details values(”,’OS’,’galvin’);

insert into books_details values(”,’DBMS’,’sudarshan’);

Without wasting time, here is the listing of the Servlet:

//imports from the mysql connector
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.Driver;

import java.io.*;
import javax.servlet.http.*;//all servlet classes
import java.sql.*;//all sql classes

public class ServDb extends HttpServlet {

public void doGet(HttpServletRequest req,HttpServletResponse resp) {

try {

/*——————–Database connectivity—————————*/
/*Declare a statement object and resultset object. Statement object is used
to execute the statement and ResultSet object holds the reult of query*/
Statement stmt;
ResultSet rs;

//Register the JDBC driver for MySQL.
Class.forName(“com.mysql.jdbc.Driver”);

/*Define URL of database server
It’s of the format jdbc:database_server://hostname:port/database_name*/
String url = “jdbc:mysql://localhost:3306/books”;

//Get a connection to the database for a user with password substitute your own username and password here

//root is the default user

Connection con = DriverManager.getConnection(url,”root”, “secret”);

//Get a Statement object
stmt = (Statement)con.createStatement();

//query the database
rs = stmt.executeQuery(“SELECT * FROM books_details”);
/*——————–Database connectivity—————————*/

/*——————–Send Response to Browser—————————*/
//Send response to the browser
resp.setContentType(“text/html”);//we are sending HTML to browser
PrintWriter out = resp.getWriter();

String uname = req.getParameter(“uname”);//get the
String passwd = req.getParameter(“passwd”);
out.println(“<html>\n<head>\n<title>Try1</title>\n</head>\n<body>”);
out.println(“<p>id\tname\tauthor</p>”);
//loop through the reults until there is no next row

while(rs.next()){
int id = rs.getInt(“id”);//get book id which is int
String name = rs.getString(“book_name”);//get name which is string
String author = rs.getString(“author”);
out.println(“<p>”+id+”\t”+name+”\t”+author+”</p>”);//send to browser
}
out.println(“</body>\n</html>”);
/*——————–End Response to Browser—————————*/

//Clean Up!! Close all connections
rs.close();
stmt.close();
con.close();

}
catch (Exception ex) {
System.out.println(“Caught an exception”);
}
}
}

//We have used try..catch to essentially bypass the Exceptions.

Now, save it as ServDb.java file, and compile the servlet.The syntax is:

javac -classpath  “path to servlet-api.jar file in your tomcat directory“:”path to mysql connector downloaded”  “path to the .java file

Here is what I used on Linux system. :

javac -classpath /opt/apache-tomcat5/common/lib/servlet-api.jar:/opt/apache-tomcat5/lib/mysql-connector.jar ServDb.java

Place the class file inside tomcat_home/webapps/ROOT/WEB-INF/classes/  . Create classes directory if required. Now, edit the tomcat_home/webapps/ROOT/WEB-INF/web.xml file and add the following just before the </web-app> tag at the end of file:

<servlet>
<servlet-name>my3</servlet-name>
<servlet-class>ServDb</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>my3</servlet-name>
<url-pattern>/jdbcservlet</url-pattern>
</servlet-mapping>

Restart your tomcat server. And goto http://localhost:8080/jdbcservlet assuming that your server runs on port 8080. Change it if required.

There u are!!! If you have any problem, please use comments.

Share

Why we Indians are like this!!

No, I do not hate my country! I am an as proud citizen of India as you are. However sometimes I do think of where my country is going. Yes, India  has made tremendous progress in the last two decades. Today when India does the talk, the world stands up and listens. Clocking 7.9% growth in times when most other economies are shrinking aint no ordinary feat. India is a part of so many world forums (G8 et all) and India is expected to fulfil its responsibility at these forums in all important decisions ( Free Trade, Climate Change …). As it is said, when people begin to expect from you, you are a grown up. India has really matured in industry, services, trade, foreign relations and what not!

But pause a second and reflect on this: Can we say the same thing when it comes to fulfilling the social responsibilities within the country? Isn’t it shameful that we project our country as the epitome of secularism, at the same time we have some of the most bloody and heinous riots in our country? Aren’t we responsible for giving birth to Maoists (whom our Home Minister categorises as an as acute threat as the external one). What can one expect from the people when leaders like Madhu Koda siphon off the state money to their bank accounts. Will such a leader have the time to think of the public when he is busy thinking of methods to invest his black money? Jharkhand was envisioned as a state which would serve its people, the tribals and see what the state leaders have made of their own state! So whose fault is it, aren’t we a part of it because we select our leaders based on cast and religion? In the recent assembly elections in Maharashtra , the party championing the cause of “Marathi Manoos” at the peril of bhaiyyas of UP and Bihar, won 13 seats while the issues of development were relegated to the background. Even Haryana voted for caste and family instead of development. Why will such representatives take the pain of working for development when the voters themselves are not concerned?

When will we become socially responsible ? Exercising our franchise is one of the fundamental social responsibilities. We should not only cast our vote but caste it for the right person.

Share

Ubuntu 9.10 (Karmic Koala) : Why I love it

The Internet is abuzz with everybody vouching for Ubuntu 9.10 as the best Ubuntu edition till now. I have been using Ubuntu for good 2.5 years from the days when getting wi-fi to work was a pain in the … neck, to the days when the wi-fi on almost any computer Just Works. I had updated to and happily using 8.10 since it release and I saw no reason why I should have had updated to 9.04, though I seriously envied the improved fonts in 9.04

But the buzz around 9.10 made sure that I couldn’t resist the temptation of updating this time. And what an experience has it been! Ubuntu is now much better looking, days of the “Orange OS” are gone and there is a set of good wallpapers too. And the beauty of Karmic is not only skin deep. There are some fundamental architectural changes too, like the new ext4 filesystem is the default, grub2 is the boot loader and HALD (the daemon responsible for discovering devices like  pen drive,camera etc and notify the applications) is being phased out in favour of the better cousin DeviceKit.

Yes, Ubuntu will still not play the MP3s and avi, wmv files on first boot but you are only ” sudo apt-get install ubuntu-restricted-extras ” away from such files. And yes, the Ubuntu Software Center is now much sleeker with several GUI improvements. Several of my friends have reported that installing software through Software Center can well become an addiction! Empathy, the default IM Client in Ubuntu brings voice and video chat to gtalk users, the absence of which had kept several people from adopting Ubuntu full time. The Network Manager is just awesome, wired and wireless internet has always been easy under Ubuntu but now forget all the dirty work one had to do to surf the net through USB modems or GPRS/3G phones, you just need to know the username and password, Network Manager will do the rest. And yes, did I forget to mention that Karmic boots with a fantastic artwork in 10 seconds flat!

I can praise Ubuntu only as far as my words can go but you will have to really use it to believe me. And no, I am not saying all this because I am a Linux fanatic, Windows 7 is an awesome OS too but don’t we all like choice ? And yes, on a parting note, if you have a 64 bit processor, do give a try to 64 bit Ubuntu 9.10 , you will savour the satisfaction of giving your 64 bit processor, a matching 64 bit OS as mate!!

Share

Not able to install Windows XP after installing Linux ?

Today, a friend asked me to help with his laptop. He had installed Ubuntu (actually due to my persuation). But, yesterday XP crashed(as it does after every few months) and when he tried to reinstall XP, the XP disc simply refused to recognize his hard disk. Actually, a few other friends of mine have also had this problem and they curse Linux for it!!

The problem occurs because the hard disk in such laptops/desktops is set to use AHCI sata mode. AHCI is the acronym for the Advanced Host Controller Interface. It is a new interface specification that enables advanced SATA features like Native Command Queuing (NCQ) [gives some performance boost] and hot-plugging [enables you to attach a hard dik without rebooting the system ]. Also, according to Wikipedia: AHCI is fully supported out of the box for Windows Vista and Linux operating systems from kernel 2.6.19, and later operating systems such as Windows 7. Note, Windows XP is MISSING from the list.

So , the problem lies with XP, not with Linux! There  are a couple of solutions:

1) Use the OEM XP install CD, meaning, the XP CD which came with your laptop. The OEM CD contains required drivers for AHCI mode on that particular computer.

2)Just goto the BIOS settings and disable AHCI mode (change it to simpler and older IDE mode) and the use a vanilla XP CD (the one commonly available). The caveat is that you lose a little performance.

3)If you can, use a new Winows OS (Vista or 7 ). Or simply stay with Linux!

Share

Google Wave : Is it worth the hype ??

A few days ago, I got an invite from Google to try the Google Wave . I had been eagerly waiting for the much hyped web app from Google.

I accepted the invitation and waited for the wave to pour over me. It looked pretty nice, somewhat like a mailbox with a chat window in one corner and minimize/restore buttons on all windows. The contacts window showed four or five persons. It seems like I will have to learn to use it, I thought. Immediately I shot off invites to my friend in next room and we began experimenting. Here is what I learnt.

Whenever you want to contact somebody, you create a wave and you can add as many persons as you want from your contact to the wave. Every person that you added will receive the wave in their inbox. They can unfollow it if they wish or mark it as spam. Now when you or any of the persons on the same wave leave a reply, everyone sees it. The best part, you can edit your comments as well as those of others!! And you need not reply serially (as in chat where your sentences appear one below the other) , you can leave a reply anywhere, in the middle, end or beginning. So how do you know who edited what? Use the playback feature of the wave by which you can see the changes made by everybody frame by frame. And yes you can add Google maps and several such gadgets to your comments (the gadgets are few now but will certainly grow in number).

So, what does it have in store for a normal gmail, facebook user? Not much until all your friends are riding the wave. A good use would be kind of private group discussion. For professionals, it would be a good tool to collaborate on projects in real time. Seems like Google has found a good way to use the docs infrastructure it has already in place.

Share

Are Customers truly the KING?

I beg to differ. Recently, I went to a mobile repair shop. My Sony Erricsson phone is now out of warranty so I skipped the Service Center. However, the person at the repair shop behaved as if we had come there since we had no other option. And top of that, when my phone was repaired, after hours of waiting and then being told to come the next day, I discovered that the speakers of the phone were dead. One another round to the shop!!
What hurt me was the behavior of the shopkeeper. It was as if he was doing a service to us without taking money!!

Share

Yet another slumdog joins the blogging bandwagon

So why did I, Abhishek Kumar start blogging?

As my teachers would prefer let me answer this in points.

Everybody (friends, actors, politicians …) has one( a blog , silly!!), so why shouldn’t I?

HUMILIATION! Every magazine, newspaper I read gives so much importance to blogs that I have strted to feel that I am really missing something.

TO ATTAIN NIRVANA!! Its what you achieve through blogs (the above magazines made me believe this!!!)

To complete my Orkut, gMail, gTalk, Hotmail…… profiles. That empty “blog” field in my profile has started to haunt me in my dreams.

I didn’t get time before 17/3/2009, 9:30 am to write a blog. No, I m serious. I mean there are  other things to do in life!!!

I felt I had not yet achieved enough in life to start writing a blog. ( It doesn’t mean that on 17/3/2009, I achieved something spectacular. Actually at 9:30 am, it suddenly occured to me that it was already too late to start blogging.)

I recently became an MSP( don’t ask me, google it!) and the guys there asked me to maintain a blog.(Did I loose my credibility for the above points because of but this one reason? Please  tell me through comments)

Share