Problem Insert session id in database

Discussions

Web tier: servlets, JSP, Web frameworks: Problem Insert session id in database

  1. Problem Insert session id in database (3 messages)

    Hi All, I am working on discussion group. I have one jsp page (post.jsp)it contain two text box: subject and message field and submit button. I want when i submit this form then insert subject, message and along with "userid" in database (mysql). I have stored session id in a string variable but it show error "incompatible types found : java.lang.Object required: java.lang.String String userid= session.getAttribute("userid"); My source code: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:india","root", "prince"); String sub=request.getParameter("sub"); String message=request.getParameter("message"); String cat_name=request.getParameter("f_name"); String userid= session.getAttribute("userid"); String q="insert into message(userid, sub, message, cat_name) values(?,?,?,?)"; stmt=con.prepareStatement(q); stmt.setString(1, sub); stmt.setString(2, message); stmt.setString(3, cat_name); stmt.setString(4, userid); stmt.executeUpdate(); } Plz. give me any sugession as early as possible. Raj ^
  2. Raj, The getAttribute method has a return value of type Object. Trying to assign this to a variable of type String is the cause of your error. Try casting it: String userid = (String) session.getAttribute("userid"); Taking a few minutes to study the actual error message and a bare minimum of javadoc would also have gotten you there, really. Regards, Jeroen
  3. hat would you do with the session id once its in the database? persistenting the session id, is really only used for clustering is that what your trying to eventually do with the session id?
  4. ignore my post(comment) , i did not read the entire question :),that's my bad.