help help. database connection problem


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: help help. database connection problem

  1. #1
    Join Date
    Feb 2004
    Posts
    1

    Unhappy 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

  2. #2
    Join Date
    Feb 2004
    Posts
    1
    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

  3. #3
    Join Date
    Feb 2004
    Posts
    13

    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("jdbcdbc:"+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);
    }
    }

  4. #4
    Join Date
    Feb 2004
    Posts
    808
    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)
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center