ClassNotFound - In applet for com.microsoft.jdbc.sqlserver.SQLServerDriver

I developed this in netbeans 5.5.1, JDK 1.6

I have added the msbase, mssqlserver and msutil jar files to my libraries in netbeans. I also tried setting my class path manually in two ways

a) SET CLASSPATH=..........

b) going into system properties, environment variables etc

Now.. my applet runs in the applet viewer of netbeans just fine, but when I run it in my webpage i get the classnotfound exception.

I am running IIS (whichever version ships with xp pro).

I also tried compiling with javac -cp (classpath here) but i still get the same results..

I've tried moving the jar files into the scope of the webapp itself , and it didn't make a difference

any help would be greatly appreciated! thanks

import java.sql.*;

import java.applet.*;

import java.awt.Graphics;

publicclass connectextends Applet{

publicvoid paint(Graphics g)

{

String s = connectsql();

g.drawString(s, 5, 15);

}

public String connectsql()

{

String user="username";

String pass="password";

String url ="jdbc:microsoft:sqlserver://sql_server_name:1433;databaseName=database_name;selectMethod=cursor;";

String ret ="";

java.sql.Connection connection =null;

try

{

try{

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

connection = java.sql.DriverManager.getConnection(url, user, pass);

if (connection !=null)

{

ret ="connected";

connection.close();

connection =null;

}

else

{

ret ="failed to connect";

}

}catch(ClassNotFoundException cnfe){

ret = cnfe.toString();

}

}

catch (Exception e)

{

ret ="caught new driver exception: " + e.toString();

}

return ret;

}

}

[3164 byte] By [mike.fa] at [2007-11-27 11:42:38]
# 1

i had that problem before all i did was right click on the project go to properties and then to libraries and added the jar files

mark07a at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 2

I tried that..

"I have added the msbase, mssqlserver and msutil jar files to my libraries in netbeans"

It doesn't make a difference when I try to run the applet in my web page.. the applet viewer that comes with netbeans works fine.

mike.fa at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 3

so when you go to your project and pull down the library tab you see msbase mssqlserver and mstuil.jar along w/ like jdk and what not?

mark07a at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 4

well if that's all true did you try the library's manager under tools? and import the class file? other than that sorry dude I don't know

mark07a at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 5

right now under libraries i have

msbase.jar

mssqlserver.jar

msutil.jar

mike.fa at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 6

you don't have JDK 1.6?

mark07a at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 7

i never tried anything under library manager

what would you suggest?

creating a new library and adding the .jar files to it? then just importing that library under my projects libraries properties instead of the individual .jar files?

mike.fa at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 8

under the library category

i have

java platform (set to JDK 1.6)

then under the compile tab i have my 3 jar files listed there

mike.fa at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 9

Yup i would first try a new folder so you can keep everything together but if that doesn't work just add it directly to the class library folder then make sure you add it and import the functions you use in your executable since the path might change

mark07a at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 10

and how might i go about doing that?

do you have a tutorial or walk through for that?

mike.fa at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 11

This doesn't have anything to do with NetBeans. Your development environment uses a different classpath than the web server.

> I've tried moving the jar files into the scope of the webapp itself

How did you do that? How have you ensured that the classpath IIS is using includes those JAR files?

~

yawmarka at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 12

i moved the .jar files into the working path of my web application..

as for the class path that IIS might use, i have no idea and had no idea that it used a seperate one from the system class path

how would i set that?

mike.fa at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 13

hmmm

when i use the appletviewer in netbeans the applet runs fine.. when i run the appletviewer via command line i get the same error that i receive with my web page

why isn't the class path working properly when it compiles the class file?

mike.fa at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 14

> why isn't the class path working properly when it

> compiles the class file?

Well, it is working correctly. Your complaint is about what happens when you run the applet, not when you compile it. You haven't set up your classpath correctly in the HTML you use to run the applet.

I don't use applets so I don't recall exactly what attribute you need to specify for the classpath. But may I ask why you decided to write an applet and not an application? Applets that try to access databases are generally not a good idea for several reasons (and no, having to set the classpath properly is not one of those reasons).

DrClapa at 2007-7-29 17:45:15 > top of Java-index,Java Essentials,Java Programming...
# 15

the project is for an internal web application.. unfortunately this web application is being run on an old system that doesn't support php, asp etc etc .. so in order to have some dynamic content i wrote an applet to supply the data and i would parse it with javascript.

mike.fa at 2007-7-29 17:45:19 > top of Java-index,Java Essentials,Java Programming...
# 16

finally after searching for quite sometime a page made reference to the archive property of the applet tag

i can place my dependent jar files there.. which i did. I can now create the driver, but get a socket error.

mike.fa at 2007-7-29 17:45:19 > top of Java-index,Java Essentials,Java Programming...
# 17

sounds like your just having a rough time w/ this one lol

mark07a at 2007-7-29 17:45:19 > top of Java-index,Java Essentials,Java Programming...
# 18

> sounds like your just having a rough time w/ this one lol

That's uncalled for.

~

yawmarka at 2007-7-29 17:45:20 > top of Java-index,Java Essentials,Java Programming...
# 19

> sounds like your just having a rough time w/ this one lol

And frankly, mark07, your answers weren't helpful at all. I've noticed the same thing about your answers in several other threads, too.

Answering questions here is a good thing, the more people that provide good answers the better. And I've found myself that answering questions helps me to learn more about the topic. So I don't want to put you off from answering questions. Just, please, try to restrict your answers to something that might be helpful.

DrClapa at 2007-7-29 17:45:20 > top of Java-index,Java Essentials,Java Programming...