A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Databases
»
JDBC
Author
strange error... " before start of result set.." ???
Andres Gonzalez
Ranch Hand
Joined: Nov 27, 2001
Posts: 1561
posted
Jun 03, 2002 22:16:00
0
hey guys.. please check this out.
public class Controller extends HttpServlet { DbConnectionBroker myBroker; /** Initializes the servlet. */ public void init(ServletConfig config) throws ServletException { super.init(config); try {myBroker = new DbConnectionBroker("org.gjt.mm.mysql.Driver", "jdbc:mysql://localhost:3306/bulletin", "","",2,60, "c:\\crk\\DCB_Example1.log",0.01); } catch (IOException e5) { } } /** Destroys the servlet. */ public void destroy() { } /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); response.setContentType ("text/html"); // returns the action String action = request.getParameter("Id"); // ready to get a connection from the pool Connection conn = null; Statement stmt = null; ResultSet results,result2; //PrintWriter out = response.getWriter(); try { // Get a DB connection from the Broker conn = myBroker.getConnection(); String queryItem = "SELECT * from ITEM where C_NAME = ?"; PreparedStatement statement = conn.prepareStatement(queryItem); statement.setString(1,action); // execute query with the parameters results = statement.executeQuery(); Vector listResults = new Vector(); while (results.next()) { listResults.add(makeBean(results)); } request.setAttribute("list",listResults); if (statement != null) {statement.close();} String queryCatecory = "SELECT C_DESCRIPTION from CATEGORY where C_NAME = ?"; PreparedStatement statement2 = conn.prepareStatement(queryCatecory); statement2.setString(1,action); result2 = statement2.executeQuery(); // printing for testing purposes out.println("category is : " + result2.getString("C_DESCRIPTION")); String categoryDescription = result2.getString("C_DESCRIPTION"); request.setAttribute("categoryDescription",categoryDescription); } catch (SQLException e1) { out.println("<i><b>Error code:</b> " + e1 + "</i>"); } finally { try{if(stmt != null) {stmt.close();}} catch(SQLException e1){}; // The connection is returned to the Broker myBroker.freeConnection(conn); // out.close(); // gotoPage("/listProducts.jsp",request,response); } }
i'm getting an error:
java.sql.SQLException
: Begfore start of result set.
any ideas...
thanks
I'm not going to be a Rock Star. I'm going to be a LEGEND!
--Freddie Mercury
David O'Meara
Rancher
Joined: Mar 06, 2001
Posts: 13459
I like...
posted
Jun 03, 2002 22:47:00
0
result2 = statement2.executeQuery(); // printing for testing purposes out.println("category is : " + result2.getString("C_DESCRIPTION")); String categoryDescription = result2.getString("C_DESCRIPTION");
Is missing
result2.next();
first. Otherwise you are 'before the start of the data', you always have to move forward one spot.
Dave
[ June 03, 2002: Message edited by: David O'Meara ]
subject: strange error... " before start of result set.." ???
Similar Threads
cookies problem
Need advise with this servlet please!!!!
can anyone help me using jspsmartupload to upload an image???
Help !!!!!!! Connection problems from you know where!
Problem with DbConnectionBroker
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter