DaemonForums  

Go Back   DaemonForums > FreeBSD > FreeBSD General

FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 14th October 2008
disappearedng disappearedng is offline
Shell Scout
 
Join Date: May 2008
Posts: 128
Thanked 0 Times in 0 Posts
Default MYSQL 's fault?

Hi everyone,
I am currently using mysql 5.16 jdk 1.6 and Mysql-connector-java 5.16 to do some database stuff.

I have written the following code:

DisplayAuthor.java
Code:
[disappearedng@miuky1 ~/Desktop]$ cat DisplayAuthors.java
import java.sql.*;
import java.util.Properties;

public class DisplayAuthors     {

        static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
        static final String DATABASE_URL = "jdbc:mysql://localhost/books";

        /**
         * @param args
         */
        public static void main(String[] args)  {

                Connection connection = null;
                Statement statement = null; 

                try {
                        Class.forName( JDBC_DRIVER ); //load database driver class

                        connection = DriverManager.getConnection( DATABASE_URL, "disappearedng", "secret");
                        statement = connection.createStatement();

                        ResultSet resultSet = statement.executeQuery(
                                        "SELECT authorID, firstName, lastName FROM authors");

                        ResultSetMetaData metaData = resultSet.getMetaData();
                        System.out.println( metaData.toString());

                        int numberOfColumns = metaData.getColumnCount();
                        System.out.println( "Authors Table of Books Database: ");

                        for (int i = 1; i <= numberOfColumns; i++ )
                                System.out.printf("%-8s\t", metaData.getColumnName(i) );
                        System.out.println();

                        /*
                        resultSet.next();
                        for (int i = 1; i <= numberOfColumns; i++) 
                                System.out.printf("%-8s\t", resultSet.getObject( i ) );
                        */

                        while ( resultSet.next() )      { //next returns true iff it can position to the next role
                                for (int i = 1; i <= numberOfColumns; i++) 
                                        System.out.printf("%-8s\t", resultSet.getObject( i ) );
                                System.out.println()    ;
                        }
                }

                catch ( SQLException sqlException )             {
                        System.out.println("SQL EXCEPTION!!!!!!!!!!!!");
                        sqlException.printStackTrace();
                        System.exit( 1);
                }
                catch ( ClassNotFoundException classNotFound )  {
                        System.out.println("CLASS NOT FOUND ERROR !!!! ");
                        classNotFound.printStackTrace();
                        System.exit( 1 );
                }

                finally         {

                        try             {
                                statement.close();
                                connection.close();
                        }

                        catch (Exception exception)     {
                                exception.printStackTrace();
                        }

                }

        }
}
and this is my classpath
Code:
[disappearedng@miuky1 ~/Desktop]$ echo $CLASSPATH
/home/disappearedng//Dev/MySQL-Connector-java/mysql-connector-java-5.1.6/mysql-connector-java-5.1.6-bin.jar:.:/home/disappearedng/Dev/XML_Parser/xerces-2_9_1/*.jar
and this is the error produced when I run the compiled class:
Code:
[disappearedng@miuky1 ~/Desktop]$ java DisplayAuthors 
SQL EXCEPTION!!!!!!!!!!!!
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 0 ms ago.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
        at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2103)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)
        at DisplayAuthors.main(DisplayAuthors.java:20)
Caused by: java.net.ConnectException: Connection refused
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:519)
        at java.net.Socket.connect(Socket.java:469)
        at java.net.Socket.<init>(Socket.java:366)
        at java.net.Socket.<init>(Socket.java:209)
        at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
        at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:280)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2026)
        ... 12 more
Note that I Have SQLexception to print something so I know there is something definitely faulty with the mysql database or the way my class is compiled.

and just to let you guys see if my database is running well,
here is my db.err file:

Code:
[disappearedng@miuky1 ~/Desktop]$ sudo cat /var/db/mysql/miuky1.no-domain-set.bellcanada.err 
Password:
081014 00:11:36 mysqld_safe Starting mysqld daemon with databases from /var/db/mysql
081014  0:11:38  InnoDB: Started; log sequence number 0 83383
081014  0:11:38 [Note] Event Scheduler: Loaded 0 events
081014  0:11:38 [Note] /usr/local/libexec/mysqld: ready for connections.
Version: '5.1.22-rc'  socket: '/tmp/mysql.sock'  port: 3306  FreeBSD port: mysql-server-5.1.22
081014  0:19:46 [Note] /usr/local/libexec/mysqld: Normal shutdown

081014  0:19:46 [Note] Event Scheduler: Purging the queue. 0 events
081014  0:19:46  InnoDB: Starting shutdown...
081014  0:19:49  InnoDB: Shutdown completed; log sequence number 0 83383
081014  0:19:49 [Note] /usr/local/libexec/mysqld: Shutdown complete

081014 00:19:49 mysqld_safe mysqld from pid file /var/db/mysql/miuky1.no-domain-set.bellcanada.pid ended
081014 00:20:57 mysqld_safe Starting mysqld daemon with databases from /var/db/mysql
081014  0:20:59  InnoDB: Started; log sequence number 0 83383
081014  0:20:59 [Note] Event Scheduler: Loaded 0 events
081014  0:20:59 [Note] /usr/local/libexec/mysqld: ready for connections.
Version: '5.1.22-rc'  socket: '/tmp/mysql.sock'  port: 3306  FreeBSD port: mysql-server-5.1.22
BTW I am running on freebsd 7.0 and this is my my.conf
Code:
[disappearedng@miuky1 ~/Desktop]$ cat /etc/my.conf 
[client]
port=3306
[mysqld]
skip-bdb
port            =       3306
bind-address    =       127.0.0.1
skip-name-resolve
safe-show-database
What the hell is wrong?
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmentation fault error139 delboy FreeBSD Ports and Packages 8 9th July 2009 06:32 PM
page fault error 12 Mr-Biscuit FreeBSD General 2 23rd December 2008 11:58 AM
Segmentation fault (11) - Apache ijk FreeBSD Ports and Packages 16 15th July 2008 11:04 AM
Segmentation fault ccc FreeBSD General 8 28th June 2008 02:15 PM
MySQL C library - segmentation fault on mysql_select_db() when using CC optimisation gor OpenBSD Packages and Ports 7 10th June 2008 11:42 PM


All times are GMT. The time now is 12:59 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick