• Post Reply Bookmark Topic Watch Topic
  • New Topic

MySQL & JDBC

 
hamish cooper
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also verify that the name of "SERVERNAME" an "DATABASE" is correct.
 
Your mind is under my control .... your will is now mine .... read this tiny ad
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!