• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mysql_connect doesnt work :(

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey all, im just editing this , cos ive got some of it working, now when i type in javap com.mysql.jdbc.Driver i get this, is this correct?
C:\>c:\j2sdk1.4.2_03\bin\javap com.mysql.jdbc.Driver
Compiled from "Driver.java"
public class com.mysql.jdbc.Driver extends com.mysql.jdbc.NonRegisteringDriver{
public com.mysql.jdbc.Driver();
throws java/sql/SQLException
static {};
}

Ive wrote a small program to connect to a database with the line
con = DriverManager.getConnection"jdbc:mysql:C:\\mysql\\data\\login", "tock","tick");
the first bit is the path is to my login folder with my mysql db in, the username and password are what ive put in my my.ini file, can anyone see where im going wrong? as i keep getting this message:
Exception: Invalid authorization specification, message from server: " Access denied for user: 'root@localhost' (Using password: YES)"
previously, my my.ini file didnt have a username and password, but i seem to connect fine using my php script with this script,
$conn = mysql_connect('localhost','root','') or die("Could not connect to mysql");
even now, now that i've put a username and password into my.ini

please help im confused

Thanks
Timmy
[ February 19, 2004: Message edited by: Tim Tock ]
[ February 19, 2004: Message edited by: Bear Bibeault ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wasn't aware of that form of URL for the MySQL connection. I'd say it was wrong, but then you wouldn't be getting the error we're seeing.
Have you tried something more standard like jdbc:mysql://localhost/database ?
 
Tim Tock
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i dont understand it, i've just tried connecting to the test db with the following combinations:
con = DriverManager.getConnection("jdbc:mysql:C:\\mysql\\data\\test",
"root", "secret");
con = DriverManager.getConnection("jdbc:mysql://test",
"root", "secret");
and still i get the same error

just seen this, The root user has of course acces to all databases, while the nameless user has access to the predefined database "test" and can create and manage other databases beginning with a name beginning with "test_". If you don't want to fight with user names, access rights and passwords, then a login without user name and password and databases named test_XYZ should get you going.
so in theory i cud connect to the test db without a user name or password, again, this is what i've tried to no avail
con = DriverManager.getConnection("jdbc:mysql:C:\\mysql\\data\\test");
con = DriverManager.getConnection("jdbc:mysql:///test");
please help!!!
[ February 20, 2004: Message edited by: Tim Tock ]
 
Tim Tock
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok all i wanna do now is connect to the test database, that doesnt require a username or password, and it still doesnt work, this is the code im using, please please help, im so stressed out, keep getting the same error message

package com.stardeveloper.example;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcExample2 {
public static void main(String args[]) {

try {java.sql.Connection con;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql:C:\mysql\data\test");
if(!con.isClosed())
System.out.println("Successfully connected to MySQL server using TCP/IP...");
} catch(Exception e) {
System.err.println("Exception: " + e.getMessage());
}
}
}
[ February 20, 2004: Message edited by: Tim Tock ]
[ February 20, 2004: Message edited by: Tim Tock ]
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to make sure that the "mySQL" service is running, and then the URL to use is one of the following:
"jdbc:mysql://localhost"
"jdbc:mysql://localhost/db-name"
The second one connects to a specific database (replace "db-name" with whater your database is). If the database is not running on your local machine, then replace "localhost" with the ip-address of the machine on which it's running.
You can pass in the username and password, and additional parameters on the URL if you need, but the above will be suffient for a basic connection.
Notice that this is exactly what David suggested in the first reply. In your code examples, you're missing the "localhost/" part of the URL. It's sort'a important ...
[ February 20, 2004: Message edited by: Wayne L Johnson ]
 
Tim Tock
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi wayne,
many thanks for replying, ive tried what you said, using this line in my code
con = DriverManager.getConnection("jdbc:mysql://localhost:8080/cc301/test");
but it still doesnt work, i've got mysqladmin running, and apache as well, but i dont think that matters, still get the same error, the only thing im not too sure about is, there isnt like a main file for a mysql db, just a folder with files for the tables made within the db, unlike for example if it was a access db i wud have put test.mdb,
any other ideas?
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try:
con = DriverManager.getConnection("jdbc:mysql://localhost/test");
as David and I suggested? This assumes that the database is named "test".
 
Tim Tock
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yep tried that
same ol error:
Exception: Invalid authorization specification, message from server: "Access denied for user: 'root@localhost' (Using password: YES)"
[ February 21, 2004: Message edited by: Tim Tock ]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The fact that you are getting the access denied error says that the server is up. However, you are not supplying login credentials within your url. You need to add:
con = DriverManager.getConnection("jdbc:mysql://localhost/test?user=username&password=password");
 
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just out of curiousity, can you log on to the server locally?
>mysql -u root -p.
 
reply
    Bookmark Topic Watch Topic
  • New Topic