aspose file tools*
The moose likes JDBC and the fly likes MySQL & JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQL & JDBC" Watch "MySQL & JDBC" New topic
Author

MySQL & JDBC

hamish cooper
Greenhorn

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
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch(Exception e) {
System.out.println(e);
}




// connecting to database

try{
conn = DriverManager.getConnection

("jdbc:mysql://SQLSERVERNAME:3306/DATABASE?user=USERID&password=PASSWORD");
}



catch(SQLException se) {
System.out.println(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: http://aspose.com/file-tools
 
subject: MySQL & JDBC