NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Retrieve data from database into variable in servlet then forward it to jsp

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
kmphuthi



Joined: 11 Feb 2011
Posts: 8

PostPosted: Fri Mar 11, 2011 9:33 pm    Post subject: Retrieve data from database into variable in servlet then forward it to jsp Reply with quote

Hi All

I am developing application using jsp, servlet and MySQL. I am using stored procedures between database and servlet; that is to add, update or retrieve data. whenever I retrieve data from database I store it temporarily in the variable(s) on the servlet, then forward the same data to jsp for display. However there's nothing displayed on the jsp page but null values. what am I doing wrong? code below.

Private String g_success
try {
//database connection
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection ("jdbc:mysql://localhost:3306/hsis", "root", "admin");
CallableStatement calstat = conn.prepareCall("{call p_user_login(?,?,?)}");

//Inputs to the Procedure
calstat.setString(1, request.getParameter("g_username"));
calstat.setString(2, request.getParameter("g_password"));

//Output from the Procedure
calstat.registerOutParameter(3, java.sql.Types.VARCHAR);

calstat.executeQuery();

g_success = calstat.getString(3);

conn.close();
calstat.close();

} catch (Exception e) {
out.println(e.getMessage());
out.println(e.toString());
}

}

}

// use RequestDispatcher to forward request internally
String url = "index.jsp";

RequestDispatcher dispatcher = request.getRequestDispatcher(url);
try {
if (dispatcher != null) {
dispatcher.forward(request, response);
}
} catch (Exception ex) {
ex.printStackTrace();
}
Back to top
kmphuthi



Joined: 11 Feb 2011
Posts: 8

PostPosted: Sat Mar 19, 2011 9:44 pm    Post subject: Retrieve data from database into variable in servlet then forward it to jsp Reply with quote

Hi All

I got solution to this issue. I just stored the value of the variable in servlet context and then accessed it
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo