Results 1 to 11 of 11
  1. #1
    Preethi is offline Member
    Join Date
    Jan 2008
    Posts
    83
    Rep Power
    0

    Default Problem in connecting to database..

    I tried to connect to the database from applet(embedded in html)..But i'm getting nullPointer exception..
    ava.lang.NullPointerException
    at xmlTrail.XMLReading.fileParsing(XMLReading.java:99 )
    at xmlTrail.MD2$Imagepanel.prepareData(MD2.java:517)
    at xmlTrail.MD2$Imagepanel.<init>(MD2.java:139)
    at xmlTrail.MD2.init(MD2.java:56)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Exception in thread "thread applet-xmlTrail/MD2.class" java.lang.NullPointerException
    at sun.plugin.util.GrayBoxPainter.showLoadingError(Un known Source)
    at sun.plugin.AppletViewer.showAppletException(Unknow n Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    But i have signed the jar file..But i could able to read the data from the database from a normal java program the command i used for signing the applet
    c:/>keytool -genkry -keyalg rsa -alias yourkey
    password:
    keytool -export -alias yourkey -file yourcert.crt

    please help me....

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, an NPE has nothing to do with the signing, and everything to do with your code. You dereference something on line 99 of the file XMLReading.java that hasn't been defined up to that point (which is exactly what the exception told you).

  3. #3
    Preethi is offline Member
    Join Date
    Jan 2008
    Posts
    83
    Rep Power
    0

    Default

    This 99th line is:
    Statement stm=connection.createStatement();
    Using the same code i can able to connect to the database in normal java program.The problem is when i try to connect through the applet..'ll be there any security settings in database?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Preethi View Post
    This 99th line is:

    Using the same code i can able to connect to the database in normal java program.The problem is when i try to connect through the applet..'ll be there any security settings in database?
    Then connection is null. At the spot in your code where you define the connection, do you have an empty catch block?

  6. #6
    Preethi is offline Member
    Join Date
    Jan 2008
    Posts
    83
    Rep Power
    0

    Default

    I'm executing this program in a server from the server...
    in that server,iexplore was not java enabled..
    The same code is working fine from all other server for the same sql server...
    Only in particular server its not working...

    I have add printstack in catch section,
    Now its throwing exception as


    java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]Error establishing socket.
    at com.microsoft.jdbc.base.BaseExceptions.createExcep tion(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getExceptio n(Unknown Source)
    at com.microsoft.jdbc.base.BaseExceptions.getExceptio n(Unknown Source)
    at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<in it>(Unknown Source)
    at com.microsoft.jdbc.sqlserver.SQLServerImplConnecti on.open(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.getNewImplC onnection(Unknown Source)
    at com.microsoft.jdbc.base.BaseConnection.open(Unknow n Source)
    at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at xmlTrail.XMLReading.fileParsing(XMLReading.java:87 )
    at xmlTrail.MD2$Imagepanel.prepareData(MD2.java:517)
    at xmlTrail.MD2$Imagepanel.<init>(MD2.java:139)
    at xmlTrail.MD2.init(MD2.java:56)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    java.lang.NullPointerException
    at xmlTrail.XMLReading.fileParsing(XMLReading.java:10 1)
    at xmlTrail.MD2$Imagepanel.prepareData(MD2.java:517)
    at xmlTrail.MD2$Imagepanel.<init>(MD2.java:139)
    at xmlTrail.MD2.init(MD2.java:56)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

  7. #7
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    looks like a firewall or other networking problem to me.

    You should be able to connect, the usual error is a "access refused" from the database because of GRANT problems.

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    See, never simply ignore exceptions (except maybe when closing things, since you can't really recover from those anyway).

    This exception
    Java Code:
    java.sql.SQLException: [Microsoft][SQLServer JDBC Driver]Error establishing socket.
    means (probably because of network conditions, such as a firewall as suggested above) that you were not able to create a connection, hence connection was null, which lead to your NPE.

    You should be either aborting execution, or attempting something else, at the connection exception, rather than simply blindly continuing, assuming that the connection is there (it obviously isn't), that's what exceptions are for.

  9. #9
    Preethi is offline Member
    Join Date
    Jan 2008
    Posts
    83
    Rep Power
    0

    Default

    I'm getting this exception only when i try to connect db thro' applet...but from normal program i can able to connect to db..y such difference?

  10. #10
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Applets live in a security sandbox. The rules are very strict. Its been a while, I don't remember them. But I would not be surprized if you can't do this per the rules.

    Is the database server on the client's machine? Is it on the same machine as the webpage and applet jar file?

  11. #11
    Preethi is offline Member
    Join Date
    Jan 2008
    Posts
    83
    Rep Power
    0

    Default

    the database server is in the server not in the client machine...
    what i'm wondering is to the same database server i can able to connect to the from applet...only from a particular server i couldn't....

Similar Threads

  1. connecting to a database
    By mxb7642 in forum JDBC
    Replies: 5
    Last Post: 09-08-2009, 09:39 AM
  2. Connecting database from Applet
    By Preethi in forum New To Java
    Replies: 5
    Last Post: 05-21-2008, 09:14 AM
  3. Connecting to a database
    By peiceonly in forum New To Java
    Replies: 2
    Last Post: 04-06-2008, 03:28 PM
  4. problem in connecting to mysql database
    By nancyv in forum Java Servlet
    Replies: 6
    Last Post: 04-02-2008, 12:33 PM
  5. Problem connecting to my Database using Java
    By javaneed in forum New To Java
    Replies: 3
    Last Post: 08-13-2007, 10:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •