This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JDBC and the fly likes i couldn't run jdbc progam in netbeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "i couldn Watch "i couldn New topic
Author

i couldn't run jdbc progam in netbeans

Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
i run my jdbc program in eclipse its running fine

but same program in netbeans not running.


Perform for today. Adapt for tomorrow.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

Rahul Shilpakar wrote:i run my jdbc program in eclipse its running fine
but same program in netbeans not running.

Please TellTheDetails, any exceptions or any other observations?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Vijitha Kumara wrote:
Rahul Shilpakar wrote:i run my jdbc program in eclipse its running fine
but same program in netbeans not running.

Please TellTheDetails, any exceptions or any other observations?





I added mysql-connect jar in library of the both Eclipse & NetBeans.




When i run this program in NetBeans it gives me Output like follow -

init:
deps-jar:
compile-single:
run-single:

Cannot connect to database server

BUILD SUCCESSFUL (total time: 4 seconds)

--- Output finish ----

Note: 'Cannot connect to database server' is written in System.out.println .



Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Vijitha Kumara wrote:
Rahul Shilpakar wrote:i run my jdbc program in eclipse its running fine
but same program in netbeans not running.

Please TellTheDetails, any exceptions or any other observations?





I added mysql-connect jar in library of the both Eclipse & NetBeans.




When i run this program in NetBeans it gives me Output like follow -

init:
deps-jar:
compile-single:
run-single:

Cannot connect to database server

BUILD SUCCESSFUL (total time: 4 seconds)

--- Output finish ----

Note: 'Cannot connect to database server' is written in System.out.println .


Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Any reason you chose to replace the meaningful message in the exception with the less helpful "Cannot connect to database server"? If you get the stack trace details you should have a clue what is happening.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Paul Sturrock wrote:Any reason you chose to replace the meaningful message in the exception with the less helpful "Cannot connect to database server"? If you get the stack trace details you should have a clue what is happening.


Thanks Paul for valuable suggestion.

Now i replaces the simple message of error with the e.printStackTrace(); in my program.



And now the output of the program is as follows: ------- output ---------------

deps-jar:
Compiling 1 source file to C:\Users\HP\Documents\NetBeansProjects\howami\build\classes
compile-single:
run-single:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.SocketException: Invalid argument: connect

STACKTRACE:

java.net.SocketException: java.net.SocketException: Invalid argument: connect
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:156)
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:185)
at dbclas.ConnectToDB.main(ConnectToDB.java:35)


** END NESTED EXCEPTION **



Last packet sent to the server was 16 ms ago.
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2741)
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:185) at dbclas.ConnectToDB.main(ConnectToDB.java:35)
BUILD SUCCESSFUL (total time: 0 seconds)

-------- output finished ------------------

thank again.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2477
    
    7

I might be nitpicking, but the proper way to load the driver is:
Class.forName ("com.mysql.jdbc.Driver").newInstance () ;

Don't call newInstance(). It is not needed, and is not as the Oracle Sun guidelines explains how to load drivers.

(however, this is not the cause of the problem you reported. For that, can you try what is explained here?)


OCUP UML fundamental and ITIL foundation
youtube channel
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

Before anything else, are you able to login to MySQL directly (i.e: from a shell/command prompt)?
Rahul Shilpakar
Ranch Hand

Joined: Aug 29, 2006
Posts: 132
Vijitha Kumara wrote:Before anything else, are you able to login to MySQL directly (i.e: from a shell/command prompt)?


yes i am able to login in to MySQL Query browser as well as MySQL Administrator.

I can fire queries ans see the output.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

Ok. Are you able to run the same program outside any IDE and connect to the DB successfully,as you already done that inside Eclipse?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i couldn't run jdbc progam in netbeans
 
Similar Threads
problem with jdk 1.5
connection error when running web aplication using Tomcat 6.0
Java Program accessing Windows-DLL with JNI. Running in Netbeans but not with java.exe
JDBC ODBC Connection
java.net.BindException: Address already in use: JVM_Bind in port 1527