Thursday, July 30, 2009

Sample code for accessing mySQL from java

import java.sql.*;


public class DBConnect {

/**
* @param args
*/
public static void main(String[] args) {

Connection connection = null;

try {
String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver
Class.forName(driverName);
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/databaseName", "userName", "password");
}
catch (Exception e) {
e.printStackTrace();
}

Statement stmt;
String s;
String own;

try {
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM pet");
while (rs.next()) {
// Get the data from the row using the column name
s = rs.getString("name");
own = rs.getString("owner");
System.out.println(s + " owned by " + own);
}
}
catch (SQLException e) {
e.printStackTrace();
}
}

}

Tuesday, July 28, 2009

My adventures with DB

First step

I was introduced to MS access when I was about 12 years old. To be frank I understand nothing then.

Rebirth

My 2nd introduction to DB was when I was 24 to Oracle. since then I have been studying DBs.

Following is solely my opinion and I do not recommend anyone to follow them. Of course no liability what so ever will be admitted.

MS Access

Our little friend. The best place to get started with DB.

Pros:
1. Intuitive interface
2. Easy imports and exports to other file formats.
3. Easy installation
4. No maintenance

Cons:
1. Poor SQL interface
2. Cannot be used as fully pledged DB server


MySQL
The free guy with lot of talents

Pros:
1. Free
2. Production level DB server
2. Easy to install

Cons:
1. No built GUI


Oracle

Pros:
1. Production level
2. Free version is available

Cons:
1. Messy to maintain.
2. Messy to get started
3. No built in GUI


DB interfaces

DB interfaces add GUI to oracle and mySQL servers

Toad for mySQL

Pros:
1. Free
2. Easy installation
3. Intuitive interface

Cons:
1. One query at a time
2. Importing data from other file formats is bit poor.

Toad for Oracle

Pros:
1. Good functionality
2. Concurrent connections
3. Lot of tools to manage the DB

Cons:
1. Cluttered window. Not even slightly intuitive
2. Free version is a crippled version


SQL developer

Pros:
1. Free
2. Nice object browser
3. Very intuitive interface

Cons:
1. Support only xls and csv file imports

PL/SQL developper

Pros:
1. Intuitive interface

Cons:
1. Lower level support for maintenance

Tuesday, March 24, 2009

Intergrated light out : HP proliant

HP proliant servers come up with an interesting remote management tool : iLO

The inbuilt one is the basic iLO which is a crippled version of advanced iLO. Basic iLO does not have many feature such as remotely viewing the screen and mounting remote media.

You need to purchase a license for the Advance iLO. As an option you may get a free evaluation licence for 60 days.

One of the disadvantages I observed in iLO is that its screen is not very sensitive. That means it cannot recognize if you move the mouse fast across the screen

Sunday, December 7, 2008

Error 530 Must perform authentication before identifying USER in FTP

This is one of most annoying issues you face when using ftp server in Red Hat linux. The solution is very straight forward.

Open the gssftp file. It is normally located at /etc/xinetd.d

Change the line "Server_args = -l -a'

to

"server_args = -l"

Then restart the ftp server

Saturday, December 6, 2008

Changing appBase in Tomcat 6

AppBase is the location where the Tom cat server searches for jsp files when called by a client. Default location is the webapps folder in tom cat home.

Changing this appBase involves bit of identifying the architecture of tom cat.

First thing you should remember is that every web application you are going to deploy should be in a separate folder. You cannot directly use that folder as the appBase. Instead you have to use parent folder.

eg: If your web application is at C:/myWebApps/firstwebApp, you have to use C:/myWebApps as the appBase.

Then calling the file C:/myWebApps/firstwebApp/hello.jsp can be done by http://localhost:8080/firstwebApp/hello.jsp


If you want to call the file C:/myWebApps/firstwebApp/hello.jsp just typing the URL http://localhost:8080/hello.jsp you have to rename the folder 'firstwebApp' with 'ROOT'.

Sorry for the lengthy description but first things first.

Then how to change the appBase.

  • Open conf/server.xml file in the tomcat home foulder.
  • Find the line containing Host name="localhost" appBase="webApps"
  • Change webApps with the parent folder of your web application folder.
  • Restart tomCat

Tuesday, December 2, 2008

Command line

Command line, MS DOS prompt, bash or any other command line utility should be familiar to you. AS most of people say they were used in ancient times. But still we use them, don't we? If we are using ssh what else do we have?

Need for a new generation of command lines

We all are familiar with IDEs. They provide us lot of helps when coding. Can't we create a ssh client that would help to type commands. For example when we type 'c' it should provide help listing all the commands starting with c along with their arguments.

Is there a tool like that? Or will I have to create such a tool?

Monday, December 1, 2008

Puppy Linux

I was looking for a good light weight OS to be used in virtual PC. Yesterday came across 'puppy linux'. Puppy linux is so small with only 96MB. Loads into RAM and runs pretty fast.

Still I'm studying puppy linux. Await more details.