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?

Your rating: None Average: 2 (1 vote)

Driver in classpath?

Make sure the jar with the driver is in the classpath

Steps 1) Check the URL

Steps
1) Check the URL "dbc:db2://localhost:50000/r_m"
2) Need to set classpath for that jar file..(jdbc:db2).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <p> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br /> <br> <strike>
  • Lines and paragraphs break automatically.
  • Use <!--pagebreak--> to create page breaks.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
Just checking to see if you're an actual person rather than a spammer. Sorry for the inconvenience.