• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i couldn't run jdbc progam in netbeans

 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i run my jdbc program in eclipse its running fine

but same program in netbeans not running.
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?)

 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before anything else, are you able to login to MySQL directly (i.e: from a shell/command prompt)?
 
Rahul Shilpakar
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic