Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I can't connect a Mysql database

1 view
Skip to first unread message

Mats Bjornlund

unread,
Oct 12, 2001, 8:22:03 AM10/12/01
to
I am a newbie on connecting to databases and I need help in connecting
to a Mysql database.

I have installed:
1. VisualCafe V4.1a
2. Mysql
3. Mysql driver, mm.mysql-2.0.4-src.jar (extracted).
4. JRun Application Manager (up and running)

I have written the following test code:
import java.sql.*;
public class DBTest {
// localhost = 127.0.0.1
static String dbUrl = "jdbc:mysql//127.0.0.1:3306/menagerie";
Connection conn = null;

private void start() {
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
System.out.println("A0:");
conn = DriverManager.getConnection(dbUrl);
System.out.println("A1:");
} catch (InstantiationException e) {
System.out.println("Error: InstantiationException");
} catch (ClassNotFoundException e) {
System.out.println("Error: ClassNotFoundException");
} catch (IllegalAccessException e) {
System.out.println("Error: ClassNotFoundException");
} catch (SQLException E) {
System.out.println("Error: SQLException");
}
}
public static void main(String [] args) {
DBTest t = new DBTest();
t.start();
}
}

When I run this I get the following result (error):
A0:
Error: SQLException

Indicating, that the DriverManager can't get do a connection !

What do I have to do, to be able to connect to the database ?

Do I need an Internet Server (Apache or is it enough with JRun ?) ? Do
I have to setup the JRun (and how do I do that) ? Is my dburl wrong (I
want to just run local on my machine) ?

Thanks in advance!
Mats

Jon Skeet

unread,
Oct 12, 2001, 8:37:45 AM10/12/01
to
Mats Bjornlund <mats.bj...@capgemini.se> wrote:
> When I run this I get the following result (error):
> A0:
> Error: SQLException
>
> Indicating, that the DriverManager can't get do a connection !
>
> What do I have to do, to be able to connect to the database ?

Well, it would help if you actually showed what the exception told
you... exceptions generally contain messages which tell you what went
wrong. Without seeing what's in the exception, it could be almost
anything.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Ian Warner

unread,
Oct 13, 2001, 7:08:07 AM10/13/01
to
Have you copied/pasted your code extract? If so your URL is malformed. You
are missing a colon after "jdbc:mysql", ie, it should be
"jdbc:mysql://127.0.0.1:3306/menagerie". If you e.printStackTrace() you
will get the following SQLException.

java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:535)
at java.sql.DriverManager.getConnection(DriverManager.java:174)
at Test.main(Test.java:17)

Ian.

"Mats Bjornlund" <mats.bj...@capgemini.se> wrote in message
news:7aec40b2.01101...@posting.google.com...

0 new messages