|
FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below. |
|
Thread Tools | Display Modes |
|
|||
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(); } } } } 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 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 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 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 |
|
||||
Oddly, you don't mention anything about your network.
It might just have been my time spent shouting WTH are these exceptions from when using Rubies Net::* classes under Win32 with a restrictive firewall; but I would be inclined to believe either your system is refusing the connection or mysqld is spiting on you. Out of curiosity, what happens when you try to connect via a mysql client? Code:
$ mysql -u youruser -h yourdbhost -p yourdb ...
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
|
|||
Quote:
Quote:
Code:
[disappearedng@miuky1 /usr/home/disappearedng]$ mysql -u disappearedng -h localhost -p books Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.22-rc FreeBSD port: mysql-server-5.1.22 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> |
|
||||
I'm not a smart man when it comes to this stuff here (most people here are much so my superiors in knowledge).
But the way I do such testing, is generally via telnet for TCP based and via custom program/script for UDP based communication. telnet myhost my_protocols_port e..g tcp$ telnet foob 6789 or udp$ myscript.ext foob 6789 and see if I get a connection refused or actually get a reply of some sort. Maybe someone here knows a nicer way.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
|
|
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 |