View Full Version : Servlet connection to MS SQL

03-27-2003, 02:06 AM
hi guys....... i am having problems connecting to the sql server using java servlet. I think it may be due to the configuration of the userid and password in the ODBC settings. Here is my code below
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.internetcds.jdbc.tds.*;

public class sample extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
try {
System.out.println("Before Class " );
PrintWriter out=null;
System.out.println("Before Connection " );
java.sql.Connection Conn = (java.sql.Connection)java.sql.DriverManager.getConnection("jdbc:freetds:sqlserver:SQLServer","sa","password");

System.out.println("Before Statement" );
java.sql.PreparedStatement st = (java.sql.PreparedStatement)Conn.prepareStatement("select * from test");
java.sql.ResultSet rs = st.executeQuery();
while(rs.next()) {

} catch(Exception e) {
this code dun seem to be able to run ("jdbc:freetds:sqlserver:SQLServer","sa","password");
please advice......... thanx

03-27-2003, 10:33 AM
Did you cross posted this under a different name (= twocool ) in the MySQL forum ?:confused:

Please do not crosspost.

Why different name/user? :confused:

03-31-2003, 07:56 AM
oops haha i did not cross post
but i happen to ask him the same question b4 posting to this forum.
so i guessed he helped me by posting it here without noeing that i posted it too. sorry if this incident created any problems for anyone.