error NoClassDefFound


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: error NoClassDefFound

  1. #1
    Join Date
    Jul 2005
    Posts
    9

    error NoClassDefFound

    this is the message i get:
    java.lang.NoClassDefFoundError: com/microsoft/jdbc/sqlserver/SQLServerDriver
    at CheckUser.<init>(CheckUser.java:16)
    at MyApplet.login(MyApplet.java:138)
    at MyApplet.init(MyApplet.java:18)
    at sun.applet.AppletPanel.run(AppletPanel.java:373)
    at java.lang.Thread.run(Thread.java:595)

    when i type in the username and password,click on submit button, it gives this error. it connects to the sql database and it should compare if the username and password match with the one in the database...is this a driver problem? i loaded the driver and it works fine, because it connects to the sqlserver.

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You should also post the code that gives this exception.
    eschew obfuscation

  3. #3
    Join Date
    Jul 2005
    Posts
    9
    CODE:
    ////////////////////
    MyApplet.java
    ////////////////////
    import java.awt.*;
    import java.net.*;
    import java.io.*;
    import java.io.FileNotFoundException;
    import java.text.DateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.*;
    import java.sql.*;

    public class MyApplet extends java.applet.Applet
    {

    public String strUsername = "";
    public String strPassword = "";


    public void init() {
    if (!login()) {
    try {
    getAppletContext().showDocument
    (new URL(getCodeBase()+"accessdenied.html"),"_top");
    }
    catch (Exception e) {e.printStackTrace(); }
    }
    else {

    try {
    getAppletContext().showDocument
    (new URL(getCodeBase()+"applog.html"),"_top");
    }
    catch (Exception e) {e.printStackTrace(); }

    {
    Button myButton = new Button (" Zapiši!");
    add (myButton);
    }

    }
    }


    public boolean login() {
    boolean userValid = false;
    MyLogin login = new MyLogin (new Frame(""));

    //appendtext login = new appendtext (new Frame(""));

    requestFocus();
    try{
    if (login.id)
    {
    CheckUser check = new CheckUser();
    strUsername = login.username.getText();
    strPassword = login.password.getText();
    userValid = check.isValidLogin(strUsername, strPassword);

    System.out.println
    ("The password for " + strUsername + " is " + (userValid?"valid":"invalid"));
    }
    else
    System.out.println
    ("Zdej pa nebi vec kliku al ka ???");
    }
    catch(Exception e) {System.out.println("Napaka!!"); }
    login.dispose();
    return userValid;

    }
    }


    //////////////////////
    CheckUser.java
    /////////////////////
    import java.awt.*;
    import java.net.*;
    import java.io.*;
    import java.io.FileNotFoundException;
    import java.sql.*;


    public class CheckUser {

    // Get connection
    String serverName = "192.168.1.13";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String databaseName = "applog";
    String url = "jdbc:sqlserver://" + mydatabase +";databaseName="+databaseName+";";
    Connection connection = null;


    public CheckUser() throws Exception {
    DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
    connection = DriverManager.getConnection(url,"demo","demo");

    if (connection != null) {
    System.out.println();
    System.out.println("Successfully connected");
    System.out.println();
    // Meta data
    DatabaseMetaData meta = connection.getMetaData();
    System.out.println("\nDriver Information");
    System.out.println("Driver Name: "
    + meta.getDriverName());
    System.out.println("Driver Version: "
    + meta.getDriverVersion());
    System.out.println("\nDatabase Information ");
    System.out.println("Database Name: "
    + meta.getDatabaseProductName());
    System.out.println("Database Version: "+
    meta.getDatabaseProductVersion());

    };
    }

    public boolean isValidLogin(String userName, String password) {
    boolean isOk = false;
    try {
    Statement stmt = connection.createStatement();
    ResultSet p = stmt.executeQuery("SELECT Login, Password FROM Users WHERE "+
    "Login='"+userName+"' AND Password='"+password+"'");

    if (p.next())
    isOk = true;

    }catch (SQLException se) {
    se.printStackTrace(); // login fails for db error
    }
    return isOk;
    }

    public static void main(String args[]) throws Exception {
    CheckUser test = new CheckUser();

    }
    }

  4. #4
    Join Date
    Jul 2005
    Posts
    4
    Looks more like the sql driver class is not accessible to the code.
    Make sure the classpath is set right.

  5. #5
    Join Date
    Jul 2005
    Posts
    15
    try placing making 'static' the main program

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center