i am having a Problem with disabled Cookies. i am Having a page where a User logs in with his User account. The connection itself is saved in the session, if the login was sucessfull.
request.getSession().setAttribute("connection" , connection);
the Object DBConnection, named connection in the Session, is an Object, which has got a static Connection con Object
protected static Connection con = null;
when the User logs in, the Connections gets established with
con = DriverManager.getConnection(url, this.user, this.password);
This also works with dectivated cookies. if was checking the Connection and the con Object i want to save with a System.out.println.
System.out.println(("DBConnection == null: " + connection == null));
System.out.println("Connection" connection.getCon());
//result ->
//DBConnection == null: false
//oracle.jdbc.driver.T4CConnection@15d51e5
So the Login was sucessfull. now the User leave this side and go to some other information Pages due to a button. in Here i need this connection again and i am getting it in a Servlet.
DBConnection connection = (DBConnection)request.getSession().getAttribute("connection");
with the Same System.out.println as before it gives the same result as before, when cookies are enabled. When cookies are disabled, it throws an Exception with this results:
DBConnection == null: false
java.lang.NullPointerException
So now my Question. Why does my connection break, when i have my cookies disabled?
In my mind cookies don´t have anything to deal with the connection Object, or any other Object beeing saved within a JSP?
The connection Object throwing the Nullpointer is the Object in the Package java.sql.Connection;