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:
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.
Login failed for user? But I don't see where you specify the user or the password. Perhaps you ought to do that.
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.
When you run Tomcat as a service, it is the service user (by default: LocalSystem ) that runs your program, and that is authenticated.
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).
Well that was the code for a short jsp tutorial for the databases course at my uni.
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.