CreateCoffees.java

Hi,

I am trying to execute the file which is in api document in http://java.sun.com/products/jdbc/book.html

/*

* Copyright 2003 Sun Microsystems, Inc. ALL RIGHTS RESERVED.

* Use of this software is authorized pursuant to the terms of the license found at

* http://developer.java.sun.com/berkeley_license.html.

*/

import java.sql.*;

public class CreateCoffees {

public static void main(String args[]) {

String url = "jdbc:mySubprotocol:myDataSource";

Connection con;

String createString;

createString = "create table COFFEES " +

"(COF_NAME varchar(32), " +

"SUP_ID int, " +

"PRICE float, " +

"SALES int, " +

"TOTAL int)";

Statement stmt;

try {

Class.forName("myDriver.ClassName");

} catch(java.lang.ClassNotFoundException e) {

System.err.print("ClassNotFoundException: ");

System.err.println(e.getMessage());

}

try {

con = DriverManager.getConnection(url,

"myLogin", "myPassword");

stmt = con.createStatement();

stmt.executeUpdate(createString);

stmt.close();

con.close();

} catch(SQLException ex) {

System.err.println("SQLException: " + ex.getMessage());

}

}

}

when i execute the file i have an error like that;

ClassNotFoundException: myDriver.ClassName

SQLException: No suitable driver found for jdbc:mySubprotocol:myDataSource

i am using netbeans IDE 5.5.1 and i have an mysql database.

I couldnt find where the problem is.Can you help?

[1606 byte] By [TugoSa] at [2007-11-27 8:50:16]
# 1

> when i execute the file i have an error like that;

> ClassNotFoundException: myDriver.ClassName

You have to specify the actual driver class (fully-qualified) for your driver.

> SQLException: No suitable driver found for

> jdbc:mySubprotocol:myDataSource

You have to specify the actual connection url.

> I couldnt find where the problem is.Can you help?

The problem is that you aren't reading carefully.

aniseeda at 2007-7-12 21:01:04 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
This might help http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html
yorkroada at 2007-7-12 21:01:04 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...