| | |
MySql connection question.
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Jul 2006
Posts: 138
Reputation:
Solved Threads: 0
Hi,
I just installed MySQL on my computer and went though a decent MySQL tutorial. Now I need you guys help me out so I can get my java programs to connect to MySQL.
I am using the following code from a book to connect.
When I run the program I get the following error. Even afer googling all the lines I can't seem to figure out what the problem is. Any help will be appreciated.
I just installed MySQL on my computer and went though a decent MySQL tutorial. Now I need you guys help me out so I can get my java programs to connect to MySQL.
I am using the following code from a book to connect.
Java Syntax (Toggle Plain Text)
import java.sql.*; public class Hello{ Connection connection; private void displaySQLErrors(SQLException e) { System.out.println("SQLException: " + e.getMessage()); System.out.println("SQLEXception: " + e.getSQLState()); System.out.println("VendorError: " + e.getErrorCode()); } public Hello() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch (Exception e) { System.err.println("Unable to find and load driver"); System.exit(1); } } public void connectToDB() { try { connection = DriverManager.getConnection( "jdbc:mysql://localost/accounts?user=userName&password=passwd"); } catch(SQLException e) { displaySQLErrors(e); } } public void executeSQL() { try { Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery("SELECT * FROM acc_acc"); while (rs.next()) { System.out.println(rs.getString(1)); } rs.close(); statement.close(); connection.close(); } catch (SQLException e) { displaySQLErrors(e); } } public static void main(String[] args) { Hello hello = new Hello(); hello.connectToDB(); hello.executeSQL(); } }
Java Syntax (Toggle Plain Text)
SQLException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.UnknownHostException MESSAGE: localost STACKTRACE: java.net.UnknownHostException: localost at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:849) at java.net.InetAddress.getAddressFromNameService(InetAddress.java:1183) at java.net.InetAddress.getAllByName0(InetAddress.java:1136) at java.net.InetAddress.getAllByName0(InetAddress.java:1109) at java.net.InetAddress.getAllByName(InetAddress.java:1072) at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:137) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:276) at com.mysql.jdbc.Connection.createNewIO(Connection.java:2666) at com.mysql.jdbc.Connection.<init>(Connection.java:1531) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:207) at Hello.connectToDB(Hello.java:25) at Hello.main(Hello.java:55) ** END NESTED EXCEPTION ** Last packet sent to the server was 18 ms ago. SQLEXception: 08S01 VendorError: 0 Exception in thread "main" java.lang.NullPointerException at Hello.executeSQL(Hello.java:35) at Hello.main(Hello.java:56)
Last edited by ryy705; Feb 2nd, 2007 at 5:17 pm.
![]() |
Similar Threads
- remote mysql connection (MySQL)
- C++ and MySQL connection (C++)
- MySQL++ query question (C++)
- Problems installing MySQL++ wrapper for C++ language (C++)
- jsp with mysql connection (JSP)
- Local Area Connection Question (Network Security)
- modem connection question... (OS X)
Other Threads in the Java Forum
- Previous Thread: Super-power compare method? <?>
- Next Thread: ServletContextAttributeListener not working
Views: 4337 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android api apple applet application arguments array arrays automation binary block bluetooth chat class classes client code compile component database developmenthelp draw eclipse encode error event exception file fractal freeze game gameprogramming givemetehcodez graphics gui helpwithhomework html ide image input integer iphone j2me j2seprojects java javac javaprojects jmf jni jpanel julia lego linux list loop loops mac map method methods mobile netbeans newbie notdisplaying number object online oracle print problem program programming project recursion scanner screen server set singleton size sms socket sort sql string swing system template test textfields threads time title transfer tree tutorial-sample update windows working






