I'm trying to display a table from sql server with local connection(everything is in my computer). I'm using netbeans, apache tomcat as a service, sql server express 2008(using windows authentication) and I have the following code:
<%@ page language="java" import="java.sql.*"%>
<title> Northwind: JSP and SQLServer 2005 </title>
catch (ClassNotFoundException e)
out.println("<h1>Driver not found:" + e + e.getMessage()+ "</h1>" );
Connection conn = DriverManager.getConnection("jdbc:sqlserver://MICHAEL-PC\\SQLEXPRESS:1433;database=Northwind;Integrated Security=True");
Statement stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM Employees");
out.println( "<table>" );
while ( rs.next() )
String id = rs.getString("EmployeeID");
String ln = rs.getString("LastName");
String fn = rs.getString("FirstName");
String ti = rs.getString("Title");
out.println( "</table>" );
} catch (Exception e)
out.println( "<h2>Exception: "+e.getMessage()+"</h2>" );
After 3 or 4 exceptions I copied the sqljdbc4.jar in "C:\Users\Michael\Documents\NetBeansProjects\TestJDBC\build\web\WEB-INF\lib" folder,
I changed the TCP Port to 1433 (through configuration manager>Network configuration>Protocols for SQLExpress>TCP/IP>IPAll),
also tried to include to the library of the web project the sqljdbc4.jar but still no go.
I'm also using the odbc-jdbc bridge for the connection.
So, the latest error i'm getting when trying to run the project is: Exception: Login failed for user ''.
I've read solutions from others and the were saying to change the server authentication from windows authentication to sql server and windows authentication mode but it didn't work with me.
Please any suggestions would be more than helpful.
Thank you in advance.
And why on earth are you doing that code in a JSP? That's just about the worst possible choice of tool for debugging this sort of thing. Besides which you shouldn't have that code in a JSP anyway. Get it out of the view and put it in the model (a servlet or a supporting bean) where it belongs.
Run Tomcat service under a named user, and give proper rights to that user in SqlServer
Don't use Windows Authentication
Use Tomcat's built in mechanism to register data sources, in stead of setting the connection in your JSP.
Don't embed java code in your JSPs (not a good practice).
At the cslab we are using a username and a password and everything is ok, but at home with windows authentication things are getting unconfortable.
I'll give it a try with sql server authentication.