coming from a php background i'm completely lost in the JAVA architecture. this is my first desktop app in over 10 yrs, and my first Java app. So pardon the noob questions.
I use netbeans 7.0.1 + JDK 1.7.0. Create new desktop appliction, with just a single button. do the "import java.sql.*;" at the top of the "DesktopAppView.java" page. I went to library then added the MYSQL JDBC driver. Even downloaded and added the latest JDBC connection from MYSQL site.
went to the services panel, right click on Drivers, MySQL (Connector/J driver) and added new connection and was able to connect to the DB.
then in the button click function in "DesktopAppView.java" page, i added:
//String driver = "com.mysql.jdbc.Driver";
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:mysql://localhost/test";
String username = "root";
String password = "";
Class.forName(driver); // load MySQL driver
//Class.forName(driver).newInstance(); // load MySQL driver
Connection conn = DriverManager.getConnection(url, username, password);
System.out.println("done");
When it comes to the "getConnection" part, application just hangs. When i added a "?connectTimeout=3000" to the url string, it timedout the app raising exception :
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure...
......
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.net.SocketTimeoutException: Connect timed out
at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:125)
however, when creating a java application in netbeans (not desktop app).. the same connection code works fine???
I'm pulling my hair out over the last two days. I'm not sure what stuff is added to teh desktop app that maybe conflicting with the DB connection.
I have already tried all posted here by SOheil... Solving a "communications link failure" with JDBC and MySQL Nothing works
PLs HELP !!!