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.
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
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 */ }
}
}
}
}