Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java servlet database connection error

843810Jul 13 2006 — edited Aug 18 2007
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.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 15 2007
Added on Jul 13 2006
2 comments
589 views