Results 1 to 3 of 3
  1. #1
    saran87 is offline Member
    Join Date
    Jul 2009
    Location
    india
    Posts
    9
    Rep Power
    0

    Default Add Serial No In output

    Hi,this is my query..i want serial no..so what i write in the query for getting sl no
    query = "SELECT Invoiceno, InvoiceDate, TotalAmount FROM tblInvoice WHERE InvoiceDate BETWEEN ? AND ? ";

    statement2 = connection2.prepareStatement(query);

    statement2.setString(1 , fromDates);

    statement2.setString(2 , toDates);

    resultset = statement2.executeQuery();

    while(resultset.next())


    invoiceList1.add(resultset.getString(1));
    invoiceDateList1.add(resultset.getString(2));
    invoiceAmtList1.add(resultset.getString(3));
    Thanks In Advance.........

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    not sure what you mean by serial number ?

    for jdbc, why not read each row into an array of beans, instead of arrays of individual properties ?

    for example, create an InvoiceItem bean

    Java Code:
    public class InvoiceItem {
    	String invoiceNumber;
    	String invoiceDate;  // TODO: maybe use a Date ?
    	String totalAmount;  // TODO: maybe use a Double? 
    	
    	public void setInvoiceNumber(String invoiceNumber) { this.invoiceNumber = invoiceNumber; }
    	public String getInvoiceNumber() { return this.getInvoiceNumber; }
    	
    	public void setInvoiceDate(String invoiceDate) { this.invoiceDate = invoiceDate; }
    	public String getInvoiceDate() { return this.getInvoiceDate; }
    
    	public void setInvoiceAmount(String invoiceAmount) { this.invoiceAmount = invoiceAmount; }
    	public String getInvoiceAmount() { return this.getInvoiceAmount; }
    	
    }
    and then this method becomes
    Java Code:
    public List<InvoiceItem> getInvoiceItems(Connection con, String fromDate, String toDate) throws SQLException {
    	List<InvoiceItem> results = new ArrayList<InvoiceItem>
    	PreparedStatement stmt = null;
    	ResultSet resultSet = null;
    	try {
    		String query = "SELECT Invoiceno, InvoiceDate, TotalAmount FROM tblInvoice WHERE InvoiceDate BETWEEN ? AND ? ";
    		
    		stmt = con.prepareStatement(query);
    		stmt.setString(1, fromDate);
    		stmt.setString(2, toDate);
    
    		resultset = stmt.executeQuery();
    
    		while(resultset.next()) {
    			InvoiceItem item = new InvoiceItem();
    			item.setInvoiceNumber(resultSet.getString("Invoiceno"));
    			item.setInvoiceDate(resultSet.getString("InvoiceDate"));
    			item.setTotalAmount(resultSet.getString("TotalAmount"));
    		
    			items.add(item);
    		}
    	}
    	finally {
    		if (resultSet != null) {
    			try {
    				resultSet.close();
    			} catch (SQLException ex) { }
    		}
    		if (stmt != null) {
    			try {
    				stmt.close();
    			} catch (SQLException ex) { }
    		}
    	}
           return items;
    }

  3. #3
    raqman is offline Member
    Join Date
    Sep 2009
    Posts
    37
    Rep Power
    0

    Default

    Hi.
    As I know, RAQ Report can help users to add serial number automatically.
    Maybe you can have a try.
    Regards,
    raqman.
    RAQ Report: free Java reporting tool.

Similar Threads

  1. Serial Port
    By radhika in forum New To Java
    Replies: 5
    Last Post: 11-06-2009, 11:40 AM
  2. usb to serial converter
    By freezy in forum Advanced Java
    Replies: 2
    Last Post: 03-18-2009, 11:48 AM
  3. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-26-2009, 12:44 AM
  4. Access Serial port
    By hasani6leap in forum Advanced Java
    Replies: 0
    Last Post: 02-12-2008, 10:45 AM
  5. serial port
    By musiigedeo in forum Advanced Java
    Replies: 0
    Last Post: 07-23-2007, 05:52 PM

Posting Permissions

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