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