Hi everybody - first post. I did look around a bit but couldn't find a relevant answer, if it's a duplicate post apologies!

Anyway, using Ubuntu 7.10, NetBeans and MySQL
libmysql-java 5.0.4+dfsg-2 installed ( JDBC drivers )
I also downloaded mysql-connector-java-5.1.6.tar.gz but not quite sure what to do with it.

Can access the database from the command line so there's nothing wrong with the MySQL installation.


The following returns the error message below:

import java.sql.*; 
import java.awt.*; 
import java.awt.event.*;



public class SimpleJDBC 
{ 
   public static void main(String[] args) 
   { 
       Connection conn;
       Statement stmt;

       try 
       { 
          Class.forName( "com.mysql.jdbc.Driver" ).newInstance(); 
            
       } 
       catch (Exception ex) 
       { 
           System.out.println( "Exception is: " + ex.toString( ));
       }
        		
       try 
       {
           conn = DriverManager.getConnection("jdbc:mysql://localhost/testdb?user=user&password=password");
           
           
           stmt = conn.createStatement( );

           String strQuery = "select * from services";
           ResultSet rs = stmt.executeQuery( strQuery );
           while ( rs.next( ))
           { 
              System.out.print( rs.getString( "service" ) );
           }
				
           if ( rs != null )
           {
              rs.close( );
           }
           if ( stmt != null ) 
           { 
              stmt.close( ); 
           } 
           if ( conn != null )
           {
              conn.close( );
           }
       } 
       catch (SQLException ex) 
       {
          System.out.println("SQLException: " + ex.getMessage()); 
          System.out.println("SQLState: " + ex.getSQLState()); 
       }
   }
}

init:
deps-jar:
Compiling 1 source file to /home/dantastik/Documents/SimpleJDBC/build/classes
compile:
run:
Exception is: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
SQLException: No suitable driver found for jdbc:mysql://localhost/testdb?user=user&password=password
SQLState: 08001
BUILD SUCCESSFUL (total time: 1 second)

If anyone can give me a hand, thanks so much!!!

Dan

Recommended Answers

All 3 Replies

I also downloaded mysql-connector-java-5.1.6.tar.gz but not quite sure what to do with it.

Extract it, you will get few files one of them is JAR file (mysql-connector-java-5.1.6-bin.jar). Copy JAR file into TOMCAT_DIRECTORY/webapps/your_project_name/WEB-INF/lib , if you do not have lib directory then create one. And you done...

I think other guys can come with other solutions, but this is as simple as it can get

That was simple indeed, thanks for the quick and helpful reply :)

Dan

commented: Thank you for marking your thread as solved +7

Sometimes we just forget to do obvious thing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.