Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Applet & SQL JDBC Driver

Options
  • 15-03-2006 5:57pm
    #1
    Closed Accounts Posts: 216 ✭✭


    Hi,

    I'm tryin to create an applet that will display live updates in a sql table. I have the code working in a command prompt environment, but once I try to insert the code into an applet, I get a SQL error. I think it's something to do with the driver; the only error I get I display in the Applet and it's as follows:
    "com.microsoft.sqlserver.jdbc.SQLServerDriver".

    That's it!

    Any ideas?

    gogul


Comments

  • Moderators, Politics Moderators Posts: 39,795 Mod ✭✭✭✭Seth Brundle


    show us the code.
    have a look at this - it may help...
    http://adams.patriot.net/~tvalesky/jdbc.html


  • Closed Accounts Posts: 216 ✭✭gogul


    Hmm, that code looks good, but I want to stay away from using a JDBC-ODBC bridge. I'm just looking for a direct applet connection using JDBC only.

    The connect code is below. This works at a normal console level, but seems to have problems with applets. I have checked on this and it seems that the the error I'm having may be linked to the applet being unable to locate the driver. Only problem is, that I dont know how to successgfully link the driver with the applet.

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection con = DriverManager.getConnection("jdbc:sqlserver://127.0.0.1;databaseName=TestDB;user=user;password=password");


  • Moderators, Politics Moderators Posts: 39,795 Mod ✭✭✭✭Seth Brundle


    what about the DB port?
    DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;user=user;password=password")

    Also read this - http://support.microsoft.com/default.aspx?scid=kb;en-us;839569


  • Closed Accounts Posts: 216 ✭✭gogul


    kbannon wrote:
    what about the DB port?
    DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;user=user;password=password")

    Also read this - http://support.microsoft.com/default.aspx?scid=kb;en-us;839569


    No, I've also tried the port and it doesnt work. It's a definite driver issue


  • Moderators, Politics Moderators Posts: 39,795 Mod ✭✭✭✭Seth Brundle




  • Advertisement
  • Registered Users Posts: 4,188 ✭✭✭pH


    quick thoughts -

    Is the sqlserver.jar in the correct place on the web-server, and specified properly in the <APPLET> tag ? - check this by writing a bit of test code that referes to a class in the jar explicitly and check for a noclassdef exception.

    an applet can only connect back to the machine it came from (I believe that DNS and what the machine is called is important) Is the sqlserver on the same machine as the webserver and do you refer to them using the exact same url?


  • Closed Accounts Posts: 216 ✭✭gogul


    pH wrote:
    quick thoughts -

    Is the sqlserver.jar in the correct place on the web-server, and specified properly in the <APPLET> tag ? - check this by writing a bit of test code that referes to a class in the jar explicitly and check for a noclassdef exception.

    an applet can only connect back to the machine it came from (I believe that DNS and what the machine is called is important) Is the sqlserver on the same machine as the webserver and do you refer to them using the exact same url?

    I'm just running the applet using appletviewer in command prompt. It will never be on a website except to run locally on a machine through IE. I'm not sure how to set the <APPLET> tage properties on this? Can you help?


  • Closed Accounts Posts: 216 ✭✭gogul


    So, do I have to reference the jdk directory with the codebase tag?


  • Registered Users Posts: 4,188 ✭✭✭pH


    Are you sure you should be using an applet then?

    Depending on how you do this - if it's production code then your classes should be in a jar (signed) and that jar's manifest should specify the jars it depends on.

    However this may work:
    <applet
    CODEBASE="/where to find jars"
    code=Applet.class
    archive="YOUR.jar, mssqlserver.jar"
    width=800 height=400>
    </applet>
    
    or something similar

    Seriously why not just change it from an applet to a JFrame and run it from the PC?

    Just add a static main method
    public class MyApplet extends JApplet {
    
      ...
    
      public static void main(String[] args) {
    
        Component applet = new MyApplet();
    
        JFrame frame = new JFrame("My applet, as application");
        frame.getContentPane().add(applet);
    
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.show();
    }
    
    http://www.devx.com/tips/Tip/16650


  • Advertisement
  • Closed Accounts Posts: 216 ✭✭gogul


    pH wrote:
    Are you sure you should be using an applet then?....

    Yeah I have been thinking that alright. It was just that I am more familiar with using Applets (except when it comes to DB connections, lol). I have tried the code in a JFrame and it connects fine.

    I guess a JFrame is the best option so, but that Aplpet issue is really bugging me now. Anyway, thanks for your help on this lads.

    gogul


Advertisement