-
help help. database connection problem
i have a bit of a problem connecting to my db
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
-
the searchstring to the database should look like "jdbc:mysql:_databasename_", "username","password"); where the _databasename_ is the name of the group of tables in mysql. the default _databasename_ that comes with mysql is "mysql" and "test". Just write these names, not the whole path.
webmaster
www.research-o-matic.com
-
Try this
import java.sql.*;
import javax.swing.*;
public class DataB
{
protected Connection connection;
protected Statement statement;
public DataB( String naamDatabank ) //naamDatabank = name of your Database
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc dbc:"+naamDatabank);
}
catch(ClassNotFoundException cnfex)
{
JOptionPane.showMessageDialog(null, "jdbc odbc driver niet gevonden", "Fout", JOptionPane.ERROR_MESSAGE);
}
catch(SQLException sqlex)
{
JOptionPane.showMessageDialog(null, sqlex, "Fout", JOptionPane.ERROR_MESSAGE);
}
}
-
twofuncky: the OP is using mysql, not the JDBC/ODBC bridge. the code you posted is not applicable
ancient: im sure that the mysql documentation reads something entirely different
timmytock: why are you writing your own database driver? just read the documentation that came with the mysql driver. it tells you how to install the jar, how to add it to the classpath, how to connect to the database.. it even gives sample java code, that works. (yor connection string looks like it is using a local path.. maybe you havent realised that mySql is a tcp/ip based database system, it doesnt accept local paths)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|