Connection to MySQL AB

Hello,

I can't seem to get this right.

I'm pretty sure that the problem is in this line, if not the sourc follows.

Thanks,

Jeff.

String url = "jdbc:mysql://localhost/user=root&password=password";

/*

* Main.java

*

* Created on December 5, 2005, 12:32 PM

*/

package CreateCoffees;

/**

*

* @author jspence

*/

import java.sql.*;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

public class CreateCoffees {

public static void main(String args[]) {

String url = "jdbc:mysql://localhost/user=root&password=password";

Connection con;

String createString;

createString = "create table COFFEES " +

"(COF_NAME VARCHAR(32), " +

"SUP_ID INTEGER, " +

"PRICE FLOAT, " +

"SALES INTEGER, " +

"TOTAL INTEGER)";

Statement stmt;

try {

Class.forName ("com.mysql.jdbc.Driver"); //("myDriver.ClassName");

} catch(java.lang.ClassNotFoundException e) {

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

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

}

try {

con = DriverManager.getConnection(url);

stmt = con.createStatement();

stmt.executeUpdate(createString);

stmt.close();

con.close();

} catch(SQLException ex) {

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

}

}

}

[1495 byte] By [jSpencea] at [2007-10-2 7:33:16]
# 1
And the problem would be?
CeciNEstPasUnProgrammeura at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 2
String url = "jdbc:mysql://localhost/theNameOfYourDatabase?user=root&password=password";
yawmarka at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 3
[url= http://dev.mysql.com/doc/refman/5.0/en/cj-configuration-properties.html]Driver/Datasource Class Names, URL Syntax and Configuration Properties for Connector/J[/url]
yawmarka at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 4

Here's the output. I'm using NetBeans 4.0, and

MySql AB 5.0.

init:

deps-jar:

Compiling 1 source file to C:\JavaJeff\CreateCoffees\build\classes

compile:

run:

SQLException: Access denied for user ''@'localhost' (using password: NO)

BUILD SUCCESSFUL (total time: 0 seconds)

jSpencea at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 5
This file is supposed to create the database so itdoesn't exisits.
jSpencea at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 6
> This file is supposed to create the database so it> doesn't exisits.How will you be able to connect to something that doesn't exist?Kaj
kajbja at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 7

I dunno, my guess is (i'm learnin' hear) that the database would

be created by the program. Hence the following.

createString = "create table COFFEES " +

"(COF_NAME VARCHAR(32), " +

"SUP_ID INTEGER, " +

"PRICE FLOAT, " +

"SALES INTEGER, " +

"TOTAL INTEGER)";

jSpencea at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 8
You need to connect to an existing database (縨ysql, test?) with an existing user/password (縭oot/****?) and then create the db
akimotoa at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 9
> This file is supposed to create the database so it doesn't exisits.I don't see any "Create Database" commands in that code. I do see "Create Table", though. You might want to find out what is the difference between a database and a table.
DrClapa at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 10
good point,Thanks,
jSpencea at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 11

> good point,

> Thanks,

Another good point is that MySQl is an example of a database service. So as mentioned it doesn't just magically create files. You need to be connecting to an actualy MySQL server instance (which will magically make the files for you).

Unless you trying some embedded version. But that URL sure doesn't look that is what you are doing.

jSpencea at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...
# 12
By George I think I've got it..... sorry for using space for thanking everyone..... I'll try to refrain next time.Jeff.
jSpencea at 2007-7-16 21:13:31 > top of Java-index,Java Essentials,Java Programming...