Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem connecting to mysql

Status
Not open for further replies.

litton1

Technical User
Apr 21, 2005
584
GB
Problem connecting to mysql
Hi all, i am following a bit of a tutorial on client server and connecting to a mysql database. I have been unable to get a reply from the database through the program for a couple of days. I am using the mysql-connector-java-3.0.8-stable-bin.jar but I am having very little success. The program compiles etc, it is only when running that a catch block returns false i.e. it couldn’t connect, I am assuming because the program cannot find the connector but the %classpath% seems to be correct
Code:
echo %classpath%
C:\j2sdk1.4\bin;c:\mysql\jdbc-driver\mysql-connector-java-3.0.8-stable
-bin.jar
if you need any more info please let me know
any thought on what else I could try?

Binary Intelligence, true or false?
 
Found a tutorial on the net for connecting to a mysql database,
Code:
//package com.stardeveloper.example;

import java.sql.*;

public class JdbcExample1 {

  public static void main(String args[]) {
    Connection con = null;

    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con = DriverManager.getConnection("jdbc:mysql:///test", "root", "secret");

      if(!con.isClosed())
        System.out.println("Successfully connected to MySQL server...");
       else System.out.println("con is closed");

    } catch(Exception e) {
      System.err.println("Exception: " + e.getMessage());
    } finally {
      try {
        if(con != null)
          con.close();
      } catch(SQLException e) {}
    }
  }
}

this gave an output:
Code:
expected end of input stream

** BEGIN NESTED EXCEPTION **

java.io.IOException
MESSAGE: Unexpected end of input stream

STACKTRACE:

java.io.IOException: Unexpected end of input stream
        at com.mysql.jdbc.MysqlIO.readPacket(MysqlIO.java:1096)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:626)
        at com.mysql.jdbc.Connection.createNewIO(Connection.java:1562)
        at com.mysql.jdbc.Connection.<init>(Connection.java:491)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
:346)
        at java.sql.DriverManager.getConnection(DriverManager.java:512)
        at java.sql.DriverManager.getConnection(DriverManager.java:171)
        at JdbcExample1.main(JdbcExample1.java:12)


** END NESTED EXCEPTION **


Press any key to continue...
Does this look like a problem with the connection jar file? Any help is appreciated thanks


Binary Intelligence, true or false?
 
issue resolved by downloading the latest driver and putting it into the root drive :)

Binary Intelligence, true or false?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top