File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes MySQL & JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MySQL & JDBC" Watch "MySQL & JDBC" New topic


hamish cooper

Joined: Feb 27, 2005
Posts: 4
Hello people

Problem is as follows- I have a demo java programme that connects me to a MYSQL server. Except it doesn't ! I always am returned a message stating that no SQL server can be found (the standard error message in the code). Now there is a mySQL server with the same name on the same port number I have entered in the code. Any ideas? I have a suspicion its to do with my class path directory in windows, but despite moving the sql.jar file around I get the same old error.
The bits of the connection string in capitals are where I've replaced my specific values.

// Demo program to show java connectivity to mysql database

import java.sql.*;

public class ConnectMS
public static void main(String[] args)

int i;
Connection conn = null;

// loading jdbc-odbc driver
} catch(Exception e) {

// connecting to database

conn = DriverManager.getConnection


catch(SQLException se) {

System.out.println("connection is successful!!!");
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I am new to JDBC myself. So I could be wrong, but it looks like your are trying to pass the user/password to the database server as you would pass http request parameters.

Give this method a try ...

Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Also verify that the name of "SERVERNAME" an "DATABASE" is correct.
I agree. Here's the link:
subject: MySQL & JDBC
jQuery in Action, 3rd edition