• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

i couldn't run jdbc progam in netbeans

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i run my jdbc program in eclipse its running fine

but same program in netbeans not running.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .


 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic