ResultSet returns NOTHING

New to JSP and its environment. I am trying to connect a MS SQL database. Which gives no error same time, it does not return any thing.

I tried to change the table name from the coding so that it prompt me wrong table name. But it never bothers. It means that it is even not compiling the DriverManager line. Even, I removed the classpath entries, it compiled and gave no results.. Just a guess..

Please help me the experts.

The code is given below -

<%@pageimport ="java.sql.*, java.io.*, java.util.*" %>

<%

Connection con =null;

String ss =null;

try{

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

//DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());

//Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://SANTULAN:1433;","User=meenu;","Password=meenu;");

con = DriverManager.getConnection("jdbc:microsoft:sqlserver://SANTULAN:1433;User=s;Password=zed;");

out.println("Got Connection");

String str1 = ("Select * from dbo.users");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(str1);

while (rs.next())

{

ss = rs.getString("login");

out.println(ss);

};

}

catch (SQLException e1)

{

System.err.println(e1.toString());

}

catch (ClassNotFoundException e2)

{

System.err.println(e2.toString());

}

catch (Exception e3)

{

System.err.println(e3.toString());

}

out.println("Hello");

out.println(ss);

%>

[2398 byte] By [Santulana] at [2007-11-27 2:39:23]
# 1

Does it print "Hello" when you call this JSP?

If not, than an exception is being thrown, you are just not seeing it, either because your JSP container's logging is not properly setup, or you are looking in the wrong logfile.

Change System.out in the catch blocks to out, and then see if you get something. It would be better if you knew your container well enough to know where the logfiles were, though, and how to configure the container.

You should also be printing a stacktrace in those catch blocks.

Edit: On second thought, even if it is prining "Hello" it could still be throwing an exception, Duh!

Add another out.println statement directly before the end of the try block and see if that shows up. If that one does not, then you are definately catching an exception.

masijade.a at 2007-7-12 3:01:21 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Thanks for your reply. It prints hello and null also, the value of ss. I changed the system.err with out and it gives following error -

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC] Error establishing socket

At least I know the error. Kindly help me what to do with it.

Thanking you.

Santulana at 2007-7-12 3:01:21 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
> At least I know the error. Kindly help me what to do with it.For a start, stop using JSP as a test environment. As you have already found, it is inconvenient. Write a plain old Java application to learn how to use JDBC and to debug your driver issues.
DrClapa at 2007-7-12 3:01:21 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...