Help with Java Database Connectivity

Discussion in 'Java' started by Tom, Aug 11, 2003.

  1. Tom

    Tom Guest

    Hey guys(or girls),

    I was wondering if i could get some help with Connecting to my
    Microsoft SQL server which is on my laptop.
    I have my program written and it compiles but im having problems with
    my connection to my database, or more accurately my
    Microsoft SQL Server 2000 Driver for JDBC.
    I have set my classpath so im not really sure what my problem is.

    My error is somewhere within this code.

    String url = "jdbc:microsoft:sqlserver://local:1433;User=me;Password=tom";
    connection = DriverManager.getConnection(url,User,Password);
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();


    Below is my actual error:

    java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getConnection(DriverManager.java:532)
    at java.sql.DriverManager.getConnection(DriverManager.java:172)
    at BookProject.CloudscapeDataAccess.connect(CloudscapeDataAccess.java:133)
    at BookProject.CloudscapeDataAccess.<init>(CloudscapeDataAccess.java:44)
    at BookProject.AddressBook.<init>(AddressBook.java:35)
    at java.lang.Class.newInstance0(Native Method)
    at java.lang.Class.newInstance(Class.java:232)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:582)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:511)
    at sun.applet.AppletPanel.run(AppletPanel.java:289)
    at java.lang.Thread.run(Thread.java:479)
    java.security.AccessControlException: access denied
    (java.lang.RuntimePermission exitVM)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:267)
    at java.security.AccessController.checkPermission(AccessController.java:394)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:540)
    at java.lang.SecurityManager.checkExit(SecurityManager.java:760)
    at java.lang.Runtime.exit(Runtime.java:86)
    at java.lang.System.exit(System.java:696)
    at BookProject.AddressBook.<init>(AddressBook.java:43)
    at java.lang.Class.newInstance0(Native Method)
    at java.lang.Class.newInstance(Class.java:232)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:582)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:511)
    at sun.applet.AppletPanel.run(AppletPanel.java:289)
    at java.lang.Thread.run(Thread.java:479)

    If anyone could give me a hand it would be greatly appreciated.
    Thanks for your time!
     
    Tom, Aug 11, 2003
    #1
    1. Advertisements

  2. Tom

    Roedy Green Guest

    Perhaps the problem is permission rather than connection.
    Are you trying to talk to a JDBC server on an IP different from the
    one you use to load the Applet?

    Please follow Sun naming conventions in your posts. Variables start
    with a lower case letter. see
    http://mindprod.com/jgloss/namingconventions.html
     
    Roedy Green, Aug 11, 2003
    #2
    1. Advertisements

  3. Tom

    Joe Guest


    Reverse the order of these two lines. I think you need to make a new
    instance before you create a connection. If that's not it, check your
    database logs and see if it's getting the data you think it should be
    getting.
     
    Joe, Aug 11, 2003
    #3
  4. By convention, JDBC drivers are supposed to have a static initializer that registers
    themselves with java.sql.DriverManager. The newInstance() is required on some JVMs
    (notably, Microsoft) to ensure the static initializer is run.
     
    Lee Fesperman, Aug 11, 2003
    #4
  5. Tom

    Jason Guest

    A couple of things, you have to get the Class instance before you try
    to access the driver manager to fetch the connection. Also, wrap this
    code in a a try/catch/finally block so that when something goes wrong
    the code will gracefully exit and close the connection (and any other
    db resources) before it bails out.

    Luck.
     
    Jason, Aug 11, 2003
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.