Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2003
    Posts
    4

    Unanswered: ((PreparedStatement)Stmt).getLastInsertID();

    ((PreparedStatement)Stmt).getLastInsertID();
    l'm using this in my jsp:
    long oder_id = ((PreparedStatement)Stmt).getLastInsertID();
    and it generated a servlet error:
    Method getLastInsertID() not found in interface java.sql.Preparedstatement.
    how can l correct this error?
    is it l cannot access into Microsoft Access using this method?

  2. #2
    Join Date
    Apr 2003
    Posts
    4

    Re: ((PreparedStatement)Stmt).getLastInsertID();

    <%@ page language="java" contentType="text/html" import="ShoppingBasket,Product,java.util.*" errorPage="errorpage.jsp"%>
    <%@page import="java.sql.*"%>
    <jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
    <html> <head><title>Your Order Has Been Received</title>
    </head> <body>

    <%
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection connection = DriverManager.getConnection("jdbcdbc:db1","","");
    String query = "INSERT INTO orders VALUES ('',?,?,?,?,?,?,?,?)";
    PreparedStatement Stmt = connection.prepareStatement(query);
    Stmt.setString(1,request.getParameter("firstname") );
    Stmt.setString(2,request.getParameter("surname"));
    Stmt.setString(3,request.getParameter("address"));
    Stmt.setString(4,request.getParameter("city"));
    Stmt.setString(5,request.getParameter("postcode")) ;
    Stmt.setString(6,request.getParameter("card_number "));
    Stmt.setString(7,request.getParameter("card_type") );
    Stmt.setString(8,request.getParameter("totalvalue" ));
    Stmt.executeUpdate();
    long order_id = ((PreparedStatement)Stmt).getLastInsertID();
    String order_info_query = "INSERT INTO order_info VALUES ('',?,?,?)";
    Enumeration products = basket.getProducts();
    while(products.hasMoreElements())
    {
    Product product = (Product)products.nextElement();
    Stmt = connection.prepareStatement(order_info_query);
    Stmt.setLong(1,order_id);
    Stmt.setInt(2,Integer.parseInt(product.getId()));
    Stmt.setInt(3,product.getQuantity());
    Stmt.executeUpdate();
    }

    Stmt.close();
    connection.close();
    basket.emptyBasket();
    %>

    Thanks for your order.
    It will be processed within 24 hours.<br/>
    Please note that your Order Number is No:
    <%= order_id %> <br/><br/>

    <a href="<%= response.encodeURL("shop-basket.jsp") %> ">
    <img src="images\toshop.gif" border="0"> </a>

    </body> </html>

  3. #3
    Join Date
    Apr 2003
    Posts
    9

    Re: ((PreparedStatement)Stmt).getLastInsertID();

    Originally posted by tsuki
    ((PreparedStatement)Stmt).getLastInsertID();
    l'm using this in my jsp:
    long oder_id = ((PreparedStatement)Stmt).getLastInsertID();
    and it generated a servlet error:
    Method getLastInsertID() not found in interface java.sql.Preparedstatement.
    how can l correct this error?
    is it l cannot access into Microsoft Access using this method?
    I'm not a big Java guy, but based on the error output, that method call doesn't exist. Do you have a way of showing which methods do exist or first checking if it exists?

    Ultimately, this looks more like a coding issue than a db issue.

    Cheers,
    BDKR

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •