...

View Full Version : SQL.... i havin problems



twocool
03-27-2003, 06:01 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;
Class.forName("com.internetcds.jdbc.tds.Driver");
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()) {
System.out.println(rs.getString(1));
}

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

raf
03-27-2003, 07:57 AM
("jdbc:freetds:sqlserver:SQLServer","sa","password");

This is probably not the right formum. (MySQL database !) But heres a tutorial with working code
http://www.javaalmanac.com/egs/java.sql/ConnectSqlServer.html


edit : Please do not crosspost.
Did you steel this post from someone or did you create a different user for the other post + why then?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum