Results 1 to 19 of 19
- 03-18-2010, 01:32 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 7
- Rep Power
- 0
Problem connecting to mysql database
Hey, Im pretty new to java and have been trying to connect to a sql database not on localhost. I keep geting the error
jdbc:mysql://websiteurl.com:3306/
java.sql.SQLException: Access denied for user 'myTESTusername'@'d58-110-200-85.mas9.nsw.optusnet.com.au' (using password: YES)
Process completed.
Ive changed the varibale which stores the username to "myTESTusername@websiteurl.com" but it keeps showing up as "'myTESTusername@'d58-110-200-85.mas9.nsw.optusnet.com.au" in the error message, does my internet provider optusnet blocking me or something?
Here is a copy of my code.
Java Code:import java.sql.*; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class websiteurlJDBCtest { public static void main(String[] args) throws Exception { websiteurlJDBCtest.useConnection(); } public static void useConnection() throws Exception { Class.forName("com.mysql.jdbc.Driver"); String URL = "jdbc:mysql://websiteurl.com:3306/"; System.out.println(URL); String Database = "testDATABASE"; String UserName = "myTESTusername@websiteurl.com"; String Password = "myTESTpassword"; Connection conn = null; // connection object Statement stmt = null; // statement object ResultSet rs = null; // result set object try { conn = DriverManager.getConnection(URL+Database,UserName,Password); System.out.println("Connection Established"); } catch(Exception e) { System.out.println(e); } } }
I would really appriciate any help or ideas
thanx
- 03-18-2010, 01:44 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
That message is coming from the mysql, not your client, and you changing that "value" doesn't help as mysql will use the username and the actual hostname from which the connection was attemtpted from. You need to read the MySQL manual paying attention to the User Administration portions and, in particualr, the GRANT statement portion.
- 03-18-2010, 02:55 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 7
- Rep Power
- 0
I used cpanel to create the database, the user has all privledges to that database...
- 03-18-2010, 08:22 PM #4
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Are you using some shared hosting for this?
Are you trying to connect from home PC to some remote
hosted MySQL?
Or both MySQL and your Java code are on same machine?
- 03-19-2010, 03:40 AM #5
Member
- Join Date
- Mar 2010
- Posts
- 7
- Rep Power
- 0
the code and the mysql are not on the same machine, the database is hosted remotely, im just compiling the code on my home pc
- 03-19-2010, 08:10 AM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
The user has the rights, yes, I never said he didn't, but you also need to have user@host granted those rights, and seemingly you have them granted for one host, but the user is coming from another. That is what that message means. Read that portion of the manual again.
Edit: And don't say that "you know that's not the case", because you're wanting to change the username to "username@somehost" tells me that you don't understand it, at all.
- 05-12-2010, 09:26 AM #7
Member
- Join Date
- May 2010
- Posts
- 1
- Rep Power
- 0
Problem with connection with mysql
I made the following code. I have jdbc driver in mysql connector. i have added the directory to classpath variable. Then ran the following code with jcreator which shows the error:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.
Then i tried with netbeans and it worked well. But i want to handle it manually. Anybody have any idea?? plz help...
import java.sql.*;
public class Connect
{
public static void main (String[] args)
{
Connection conn = null;
try
{
Class.forName ("com.mysql.jdbc.Driver");
String connectionUrl = "jdbc:mysql://localhost/mydatabasename" +
"user=root&password=mysecretpassword";
conn = DriverManager.getConnection (connectionUrl);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
e.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
- 05-12-2010, 09:29 AM #8
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
What do you mean handle manually? Do you mean run from comamnd line?
If so then you should provide the -cp flag pointing to the mysql driver.
- 05-12-2010, 09:34 AM #9
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Start your own thread. That post is not related to the rest of this thread in any way, shape, or form. As hint "Classpath, Classpath, Classpath".
- 07-08-2010, 06:56 PM #10
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Oh God, not again. Stop posting this trash all over the place.
- 07-11-2010, 12:13 PM #11
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
how can i provide -cp flag pointing to the mysql driver??????????????
- 07-11-2010, 01:09 PM #12
java -cp nameofjarfilewithmysqldriver.jar .....
- 07-12-2010, 05:40 AM #13
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
Yes I have the jar file. But i don't know how to install or where to copy that file
I use the code as follows-
public void Connect()
{
try
{
// Load the JDBC driver
String driverName = "com.mysql.jdbc.Driver";
Class.forName(driverName);
// Create a connection to the database
String url = "jdbc:mysql://127.0.0.1:3306/abc";
String username = "root";
String pass = "xyz";
con1=DriverManager.getConnection(url, username, pass);
}
catch (ClassNotFoundException e)
{
System.out.println("Connection Failed");
System.out.println(e);
}
catch(SQLException e)
{
System.out.println("Connection Failed1");
}
}
When I run this code I get the error-
Connection Failed
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
- 07-12-2010, 02:02 PM #14
Can you show the command line you use when you "run this code"?When I run this code I
The java program can not find a class definition. The jar file containing that class definition must be on the classpath.
- 07-15-2010, 05:47 AM #15
Member
- Join Date
- Jul 2010
- Posts
- 28
- Rep Power
- 0
I use the redhat Linux.
After running this code the messages are as follows
[root@server bhabani_press]# java NDitem
GTK Accessibility Module initialized
Connection Failed
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
- 07-15-2010, 01:22 PM #16
What jar file is the com.mysql.jdbc.Driver class in? Add that file to the classpath when using the java command:
java -classpath THEJARFILENAME.jar NDitem
- 07-22-2010, 06:14 AM #17
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
set classpath in envoronment variable
path since mysqlconnector.jar
mysqlconnector.jar put into the lib folder
- 07-22-2010, 06:15 AM #18
Member
- Join Date
- Jul 2010
- Posts
- 38
- Rep Power
- 0
set classpath in envoronment variable
path since mysqlconnector.jar
mysqlconnector.jar put into the lib folder
- 07-22-2010, 06:40 AM #19
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
problem with connecting database
By ravidasineni in forum AWT / SwingReplies: 1Last Post: 11-24-2009, 06:04 AM -
Problem in connecting to database..
By Preethi in forum New To JavaReplies: 10Last Post: 06-26-2008, 05:53 AM -
problem in connecting to mysql database
By nancyv in forum Java ServletReplies: 6Last Post: 04-02-2008, 11:33 AM -
Problem connecting to my Database using Java
By javaneed in forum New To JavaReplies: 3Last Post: 08-13-2007, 09:35 AM -
connecting to mysql database
By javagal in forum NetBeansReplies: 2Last Post: 08-04-2007, 12:36 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks