Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

jdbc



i am having problems connecting DB2 database to my Java application using NetBeans.
Here is the Code:

package app;
import java.sql.*;
import java.lang.*;
import java.io.*;
import COM.ibm.db2.jdbc.app.*;
public class Main {

public static void main(String args[]) throws IOException
{
try
{
//Loads Type 2 Driver
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");

}
catch (ClassNotFoundException e)
{
System.err.println("Could not load DB2 driver! \n");
System.err.println(e.getMessage());
System.exit(1);
}

/* Type 2 driver url */
//String url = "jdbc:db2:r_m";
String url = "jdbc:db2://localhost:50000/r_m";

String query = "select fname,id from rohit.EMPLOYEEDETAILS;";

try
{
//Connect to a database
Connection conn = DriverManager.getConnection(url,"user","password");

//Create statement for the connections
Statement stmt = conn.createStatement();

//Execute the query
ResultSet rs = stmt.executeQuery(query);

//Loop through the result and print it out
System.out.println(query);
System.out.println("\nNAME \tID");
System.out.println("----------------------------");

while (rs.next())
{
System.out.print(rs.getString(1) + " \t" );
System.out.println(rs.getString(2));
}

rs.close();
stmt.close();
conn.close();
}
catch (SQLException e)
{
System.out.println("SQL Exception: ");
System.err.println(e.getMessage());
}
}//main
} //class

When i run this program i get the following error:

run:
SQL Exception:
No suitable driver found for jdbc:db2://localhost:50000/r_m

can anyone help me?