Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

JDBC with Xampp

Hi Guys
I am trying to use JDBC with Mysql in Xampp . I have installed Xampp and even mysql connector and set the class path correctly . The program is compiling properly but whenever i run i get the error

java.lang.NullPointerException
at Data.main(Data.java:57)

The program is

import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class Data {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/trial";

public static void main(String args[])
{
Connection connection = null;
Statement statement = null;

try
{
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL ,"madhur","kapoor");
statement = connection.createStatement();
System.out.println("COnnection Established");
ResultSet resultSet = statement.executeQuery("SELECT fname FROM try");
ResultSetMetaData metaData = resultSet.getMetaData();
int numberOfColumns = metaData.getColumnCount();
for(int i=1 ; i<=numberOfColumns ; i++)
{
System.out.printf("%-8s\t",metaData.getColumnName(i));
}
System.out.println();

while(resultSet.next())
{
for(int i=1 ; i<=numberOfColumns ; i++)
{
System.out.printf("%-8s\t",resultSet.getObject(i));
}
System.out.println();

}
}
catch(SQLException sqlException)
{
sqlException.printStackTrace();
System.exit(1);
}
catch(ClassNotFoundException classNotFound)
{
classNotFound.printStackTrace();
System.exit(1);
}
finally {


try
{
statement.close();
connection.close();
}
catch(Exception exception)
{
exception.printStackTrace();
System.exit(1);
}
}


}
}

trial is the database name and try is the name of the table ...

Do help.
[2272 byte] By [mako_123] at [2007-11-11 10:05:35]