This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

MySQL & JDBC

 
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!!!");
 
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.
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic