java servlet database connection error

hey,

i have tested database connection using normal java application and it works, so i moved on to test the database connection for servlets because i need to create a mobile application that goes through the servlets to the sql server database.

below is a sample code i got from other sources:

import java.io.*;

import java.text.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.sql.*;

public class getConnection extends HttpServlet {

private java.sql.Connection con = null;

private final String url = "jdbc:microsoft:sqlserver://";

private final String serverName= "localhost";

private final String portNumber = "1433";

private final String databaseName= "Northwind";

private final String userName = "sa";

private final String password = "";

private String getConnectionUrl(){

return url+serverName+":"+portNumber+";databaseName="+databaseName;

}

public void init() {

}

public void doPost(HttpServletRequest request,

HttpServletResponse response) throws ServletException,

IOException {

String message = "";

try {

connect(userName.trim(),

password.trim());

message += "100 ok";

} catch (Throwable t) {

message += "200 " + t.toString();

}

response.setContentType("text/plain");

response.setContentLength(message.length());

PrintWriter out = response.getWriter();

out.println(message);

out.close();

out.flush();

}

public void doGet(HttpServletRequest request,

HttpServletResponse response) throws ServletException,

IOException {

doPost(request,response);

}

private void connect(String user,String pwd)

throws Exception {

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

Connection conn = java.sql.DriverManager.getConnection(getConnectionUrl(),user,pwd);

}

}

i always get the 200 java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver as the output from my midlet and not 100 ok.

please help me out, thanks alot.

[2212 byte] By [suchiatea] at [2007-10-3 0:32:56]
# 1
hey guys, i managed to solve the problem,if you guys are facing the same problem,just put the msbase.jar, msutil.jar, mssqlserver.jar into the $TOMCAT_Home\common\lib folder and it should work...Thanks for your concern.
suchiatea at 2007-7-14 17:26:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...