Help with loop in code

I have the following servlet which connects to a database and should brgin back the name of all films that an actor has stared in below is part of the servlet my problem is each time i run the servlet it just prints out "sorry there has been an error" a number of times. Can any body help me get this working?
public static int MAX_COUNT = 100;
int curr_item = 0;
private static CatalogItem addedItem[] = new CatalogItem[MAX_COUNT];
private static CatalogItem items[] = new CatalogItem[MAX_COUNT];
CatalogItem item;
CatalogItem details;
public static CatalogItem getItem(int recordingid) {
           CatalogItem item;
          for(int i=0; i<items.length; i++) {
            item = items;
          addedItem[i] = items[i];
if (recordingid==item.getrecordingid()) {
return(item);
return(null);
// Database connection
     int recordingidDB;
     String directorDB;
     String titleDB;
     String categoryDB;
     String imageDB;
     int durationDB;
     String ratingDB;
     String yearDB;
     float priceDB;
     int StockDB;
     Connection conn = null;
     try{
     Class.forName("com.mysql.jdbc.Driver").newInstance();
     } catch(Exception e) {
     System.out.println(e);
     try{
     conn = DriverManager.getConnection
("jdbc:myurl");
     // System.out.println("Connection to database successful.");
catch(SQLException se) {
     System.out.println(se);
     try{
               String category = request.getParameter("category");
     String selectSQL = "select recording_id, director, title, category, image_name, duration, rating, year_released, price, stock_count "+
     "from video_recordings " +
                    "where recording_id IN "+
                    "(select recording_id "+
                    "from video_actors "+
                    "where name ='"+request.getParameter("category")+"')";
System.out.println(selectSQL);     
     Statement stmt = conn.createStatement();
     ResultSet rs1 = stmt.executeQuery(selectSQL);
     while(rs1.next() && curr_item < MAX_COUNT){
          recordingidDB = rs1.getInt("recording_id");
          directorDB = rs1.getString("director");
          titleDB = rs1.getString("title");
          categoryDB = rs1.getString("category");
          imageDB = rs1.getString("image_name");
          durationDB = rs1.getInt("duration");
          ratingDB = rs1.getString("rating");
          yearDB = rs1.getString("year_released");
          priceDB = rs1.getFloat("price");
          StockDB = rs1.getInt("stock_count");
     item =
          new CatalogItem
          (recordingidDB, directorDB, titleDB, categoryDB, imageDB, durationDB, ratingDB, yearDB, priceDB, StockDB);
          addedItem[curr_item] = item;
items[curr_item++] = item;
int ITEM_COUNT = curr_item;
     String pagetitle = "Catalog Items";
out.println(
"<BODY BGCOLOR=\"#a00e0e\">\n" +
          "<center></center>\n" +
"<H1 ALIGN=\"CENTER\">" + pagetitle + "</H1>\n");
     // loop to go over each item in the array of catalogItem
     for(int i=0; i<addedItem.length; i++) {
     details = items[i];
     if (details == null) {
out.println("SORRY THERE HAS BEEN AN ERROR ");
     } else {  
          for(int j=0; j<MAX_COUNT; j++) {
out.println(
addedItem[j].gettitle() + "\n" +
addedItem[j].getprice() + "\n" +
addedItem[j].getstock() + "\n" );
     out.println("</BODY></HTML>");
     stmt.close();
     conn.close();
     } catch(SQLException se) {
     System.out.println(se);

ok..
1. To print the size of the resultset there is no direct way from wat i know so far. You need to work around it. This wat i normally do for testing:
String selectSQL = "select count(video_recordings.recording_id) " +
                            "from video_recordings " +
                    "where recording_id IN "+
                                             "(select recording_id "+
                                            "from video_actors "+
                                             "where name ='"+request.getParameter("category")+"')";
Statement stmt = con.createStatement() ;
ResultSet rs = stmt.executeQuery(selectSQL) ;
rs.next() ;
BigDecimal rowCount = rs.getBigDecimal(1) ;
System.out.println("Result size = " + rowCount.toString());The rowCount variable now contains the size of your query result.
2. To print the stacktrace, just add in se.printStackTrace into your catch blocks.
Additional: Can u also print something inside youe while loop to confirm that your code did enter the while loop and perform the assignment?
Maybe u can also print the addedItem[curr_item] value after you addedItem[curr_item] = item to confirm that the item was successfully assigned to addedItem[curr_item]..

Similar Messages

  • Need help with a activation code for Adobe Acrobat X Standard for my PC,, Don't have older version serial numbers,  threw programs away,  only have Adobe Acrobat X Standard,  need a code to unlock program?

    Need help with a activation code for Adobe Acrobat X Standard for my PC, Don't have older Version of Adobe Acrobat 9, 8 or 7. 

    You don't need to install the older version, you only need the serial number from your original purchase. If you don't have them to hand, did you register? If so, they should be in your Adobe account. If not you really need to contact Adobe, though it isn't clear they will be able to do anything without some proof of purchase etc.

  • HT3209 Purchased DVD in US for Cdn viewing. Digital download will not work in Cda or US? please help with new Digital code that will work

    Purchased DVD in US for Cdn viewing. Digital download will not work in Cda or US? please help with new Digital code that will work

    You will need to contact the movie studio that produced the DVD and ask if they can issue you a new code valid for Canada. Apple cannot help you, and everyone here in these forums is just a fellow user.
    Regards.

  • Help with basic ABAP code (merge internal tables, sort of...)

    Hello,
    Can someone please help write some basic code for a Basis guy with limited ABAP knowledge?
    Should be some easy points for an experienced ABAPer!
    I have identicaly structured internal tables I_A and I_B and I_C which have already been filled by function models I called.
    How will I code the following?:
    I want to read all the data of I_A into a new internal table I_MASTER (structured the same as I_A,I_B and I_C).
    Then I want to read I_B and:
    1)Update I_MASTER with NEW records
    2)Update existing records if the value of field MYFIELD in I_B is smaller than the value of MYFIELD in I_MASTER.
    Then I want to read I_C and:
    1)Update I_MASTER with NEW records
    2)Update existing records if the value of field MYFIELD in I_C is smaller than the value of MYFIELD in I_MASTER.
    Let me know if I can provide anymore information.
    Thanks in advance for you help!
    Adriaan
    Message was edited by: Adriaan
    Message was edited by: Adriaan

    Hi Adriaan ,
    I want to read all the data of I_A into a new internal table I_MASTER (structured the same as I_A,I_B and I_C).
    <b>i_master[] = i_a[] .</b>
    loop at i_b .
    read table i_master with key myfiled < i_b-myfield .
    if sy-subrc = 0 .
    append i_master from i_b .
    endif.
    endloop.
    loop at i_c .
    read table i_master with key myfiled < i_c-myfield .
    if sy-subrc = 0 .
    append i_master from i_c .
    endif.
    endloop.
    Let me know if this helped .
    Regards,
    Varun .
    Message was edited by: varun sonu

  • Help with looping and counting

    i am in a CS 1 class and need help with this loop
    /*Write a program that will allow the user to enter a character
              until the capital letter Z is entered
         The program should count the number of letters entered
              and print the total after the loop is completed*/
    here is what i have it doesn't end nor does it count and i don't know hwo to make it count also i suck at do..while loops hehe
    char b,Z=0;
              Scanner a = new Scanner(System.in);
         do
                   System.out.print("Enter a letter: "+"\n");
                   b=a.next().charAt(0);
              while (b !=Z);
    i know that its not even close to being right just help me out here
    Edited by: purplesmurf on Nov 14, 2008 7:25 PM

    The following program will count the number of chacters entered until Z is enetered.
    import java.io.*;
    class count
         public static void main(String[] args)throws IOException
              char ch;
              int cnt=0;
              DataInputStream br=new DataInputStream(System.in);
              do
              System.out.print("Enter a character:");
              ch=(char)br.read();
              if(ch!='Z')
                   cnt++;
              else
                   break;
              }while((ch=(char)br.read())!='Z');
              System.out.println("The Number of entered characters are:"+cnt);
    }

  • Need help with adjusting Javascript code to work in Adobe Edge (Countdown)

    Hello
    Im a newbie when it comes to working with Javascript and Adobe Edge and need a bit of help with adjusting some javascript code to work with Adobe Edge. A friend of mine helped me with making this javascript code: Edit fiddle - JSFiddle
    Its a simple countdown which counts down to a certain time at a certain date. What I aim to do is to add this code as a trigger on a text-element called "countdown" (within a symbol called "count").
    I have tried to do this as the code is, but it does not work. Anyone have any suggestions?
    Thanks!
    Mvh,
    Øyvind Hermans

    Hello again
    I have stumbled upon a problem with these animations; They crash the browser after viewing them a little while, usually less than 30 seconds in.
    Is this problem also occuring when you watch the animations?
    Is the countdown-code to much for the browsers to handle?
    Thanks in advance for your answers.
    Sincerely,
    Øyvind Hermans

  • Help with HTML form code

    I need help on some HTML code if at all possible.
    What I am trying to do is set up a page that someone can
    enter their name address and email into a form and when they hit
    the submit button it automatically sends them a premade email of my
    choosing that I make prior and somehow maybe embeded into the html
    code to the address that they entered? I dont know if it is
    possible but I am sure it can be.
    Thank you in advance

    Actually, you could be subject to "abuse complaints", not
    "abuse".
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "bregent" <[email protected]> wrote in
    message
    news:fb547q$b49$[email protected]..
    > >What I am trying to do is set up a page that someone
    can enter their name
    > address
    >
    > Sure, you can do it fairly easily with any scripting
    language. You need to
    > be
    > cautious about sending automated emails to anyone
    without first validating
    > that
    > they are the actual owners of the email address,
    otherwise you open your
    > site
    > up to abuse.
    >
    > >I dont know if it is possible but I am sure it can
    be.
    >
    > Huh?
    >

  • Need Help With Simple ABAP Code

    Hello,
    I'm loading data from a DSO (ZDTBMAJ) to an Infocube (ZCBRAD06). I need help with ABAP code to some of the logic in Start Routine. DSO has 2 fields: ZOCTDLINX & ZOCBRDMAJ.
    1. Need to populate ZOCPRODCD & ZOCREFNUM fields in Infocube:
        Logic:-
        Lookup /BI0/PMATERIAL, if /BIC/ZOCBRDMAJ = /BIC/OIZOCBRDMAJ
        then /BIC/ZOCPRODCD = ZOCPRODCD in Infocube
               /BIC/ZOCREFNUM = ZOCREFNUM in Infocube         
    2. Need to populate 0G_CWWTER field in Infocube:
        Logic:
        Lookup /BIC/PZOCTDLINX, if /BIC/ZOCTDLINX = BIC/OIZOCTDLINX
        then G_CWWTER = 0G_CWWTER in Infocube.
    I would need to read single row at a time.
    Thanks!

    I resolved it.

  • Would like help with treeset ,the codes that using for sorting, please ?

    hi every body. i faced a problem while writing this program, everything worked properly except this one. The program is related to Jframe and it asks the user to add three labels , three text field , one text area and three Jbuttons which are add sort and exit. i could deal with add and exit but sort, i couldn't do it properly because i don't know the codes that should be added in actionperfomed?
    These codes are :
    package gui;
    import javax.swing.SwingUtilities;
    import java.awt.BorderLayout;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import java.awt.Rectangle;
    import java.util.ArrayList;
    import javax.swing.JButton;
    import javax.swing.JTextField;
    import javax.swing.JTextArea;
    import sun.misc.Sort;
    import domain.Student;
    public class StudentFrame extends JFrame {
          * This method initializes btnAdd     
          * @return javax.swing.JButton     
         private JButton getBtnAdd() {
              if (btnAdd == null) {
                   btnAdd = new JButton();
                   btnAdd.setBounds(new Rectangle(13, 135, 59, 27));
                   btnAdd.setText("Add");
                   btnAdd.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                        btnAddClicked(); // TODO Auto-generated Event stub actionPerformed()
              return btnAdd;
         protected void btnAddClicked() {
              // TODO Auto-generated method stub
         String name = txtName.getText();
         String id = txtID.getText();
         String age = txtAge.getText();
         Student s = new Student(name , id , age);
         txtArea.setText(String.valueOf(s ));
          * This method initializes btnSort     
          * @return javax.swing.JButton     
         private JButton getBtnSort() {
              if (btnSort == null) {
                   btnSort = new JButton();
                   btnSort.setBounds(new Rectangle(95, 136, 62, 25));
                   btnSort.setText("Sort");
                   btnSort.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             btnSortClicked(); // TODO Auto-generated Event stub actionPerformed()
              return btnSort;
         protected void btnSortClicked() {
              // TODO Auto-generated method stub
          * This method initializes btnExit     
          * @return javax.swing.JButton     
         private JButton getBtnExit() {
              if (btnExit == null) {
                   btnExit = new JButton();
                   btnExit.setBounds(new Rectangle(173, 134, 61, 23));
                   btnExit.setText("Exit");
                   btnExit.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             System.exit(0); // TODO Auto-generated Event stub actionPerformed()
              return btnExit;
          * This method initializes txtName     
          * @return javax.swing.JTextField     
         private JTextField getTxtName() {
              if (txtName == null) {
                   txtName = new JTextField();
                   txtName.setBounds(new Rectangle(79, 11, 60, 23));
              return txtName;
          * This method initializes txtID     
          * @return javax.swing.JTextField     
         private JTextField getTxtID() {
              if (txtID == null) {
                   txtID = new JTextField();
                   txtID.setBounds(new Rectangle(73, 55, 65, 26));
              return txtID;
          * This method initializes txtAge     
          * @return javax.swing.JTextField     
         private JTextField getTxtAge() {
              if (txtAge == null) {
                   txtAge = new JTextField();
                   txtAge.setBounds(new Rectangle(74, 96, 61, 24));
              return txtAge;
          * This method initializes txtArea     
          * @return javax.swing.JTextArea     
         private JTextArea getTxtArea() {
              if (txtArea == null) {
                   txtArea = new JTextArea();
                   txtArea.setBounds(new Rectangle(138, 5, 154, 128));
              return txtArea;
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        StudentFrame thisClass = new StudentFrame();
                        thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        thisClass.setVisible(true);
          * This is the default constructor
         public StudentFrame() {
              super();
              initialize();
          * This method initializes this
          * @return void
         private void initialize() {
              this.setSize(300, 200);
              this.setContentPane(getJContentPane());
              this.setTitle("JFrame");
              return jContentPane;
    }Edited by: hypocrisy on Apr 26, 2009 6:51 PM

    There are three actionPerformed in that program.One for add Jbutton , Sort , and Exit
    the codes that i have added for add button after action performed are
    String name = txtName.getText();
    String id = txtID.getText();
    String age = txtAge.getText();
    Student s = new Student ( name , id , age);
    System.out.println(s);
    the codes for Exit button to make it works properly was :
    System.out.println(0);
    But when i came to Sort Button and i tried to enter many codes but it didn't sort properly so would you like to help me with the right codes :)

  • Help with some beginner code

    Hello, I am new to java and I need a bit of help with some code that I'm writing. here is the code:
    import javax.swing.*;
    public class Test{
         public static void main(String[] args){
         JOptionPane.showMessageDialog(null,"We will now build a block with *'s","Block",1);
         String input=JOptionPane.showInputDialog(null,"Type a number: ","Number",3);
         int number=Integer.parseInt(input);
         int count=0; int count2=0;
         for(count2=0; count2<number; count2++){
              for(count=0; count<number; count++){
              System.out.print("* ");
    System.exit(0);
    }Now, all I need is to build a block of *'s with the number that the user inputs. With the code that I wrote I get the correct number of *'s but not in the form of a block. They just print out in a straight line. I know this is a very simple task but could someone please help me out? What do I need to modify in my code so that the *'s print out arranged as a block like so:
    **********

    Your code only uses the print method which prints without a carriage return/line feed. So you need to add a line of code to print a carriage return/line feed. Where? well that is your task to work out.

  • Help with free unlock code

    I just purchased a 7290 that was supposed to be unlocked (apparently it is refurbished). It came from cingular originally. My carrier can't unlock it to work with their system. Can anyone help me with free unlock codes?

    Only your carrier can provide free unlock codes.
    If you contact Horizon below in my signature, they do so cheaply and reliably.
    1. If any post helps you please click the below the post(s) that helped you.
    2. Please resolve your thread by marking the post "Solution?" which solved it for you!
    3. Install free BlackBerry Protect today for backups of contacts and data.
    4. Guide to Unlocking your BlackBerry & Unlock Codes
    Join our BBM Channels (Beta)
    BlackBerry Support Forums Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • I need Help with loop

    Hello everyone this is my first time posting here, i have always find java easy(up to this point), this is my first class in programming java i am just needing help with the "for loops" i cant seem to get the program generate 10 random math questions. if you guys can please help i will appreciate it, i have been working on it for a couple of hours. I am not finished with it yet but thats the only thing i need help with.
    import javax.swing.JOptionPane;
    public class Lab5
    public static void main(String[] args)
    int num1 = (int) (Math.random() * 100 + 1);
    int num2 = (int) (Math.random() * 100 + 1);
    int sum = num1 + num2;
    int product = num1 * num2;
    int quotient = num1 / num2;
    int difference = num1 - num2;
    for (int i = 0; i > 11; i++);
    int number = (int)(Math.random()*4);
    if (number == 0 )
    String s1 = JOptionPane.showInputDialog(null, num1 + " + " + num2 + "=" );
    if(number == 1)
    String s3 = JOptionPane.showInputDialog(null, num1 + " - " + num2 + "=" );
    if(number == 2)
    String s3 = JOptionPane.showInputDialog(null, num1 + " x " + num2 + "=" );
    if(number == 3)
    String s4 = JOptionPane.showInputDialog(null, num1 + " &divide; " + num2 + "=" );

    for (int i = 0; i > 11; i++);Two problems with this line:
    1) The second part of a For loop is the constraint. You have said that for the loop to be entered, i must be greater than 11. Well since you've also told i to begin at 0, this will never happen. Thus, the loop will never enter. You may have meant less than?
    2) You put a semicolon in the line. Semicolons are used to end statements. The For loop, when used as a block with curly braces, is not a single statement and does not require a semicolon. Here's the two structures of a basic For loop:
    for(int i = 0; i <= 100; i++) {
        //this is a block. you can put multiple statements in here and they are all part of the loop
        int a = 1;
        int b = i;
    //if your loop only needs to use a single statement, no braces are required
    for(int i = 0; i <= 100; i++)
        int a = i;

  • Help with new error code (-1)!

    Hi I am trying to update my iphone 4 to ios5. When it comes to the last stage, it shows this error of -1. I am unable to find any info related to this error code. Any help with this is highly appreciated! Many Thanks. Now the phone is unusable. Previously it showed several errors including 1600 series and they are all resolved. This is the last hudrle. Please Help!
    Thanks

    Like many I experienced some issues when updating to iOS 5 (on launch day). I finally gave up on the Update option and chose the Restore option.
    iOS 5 downloaded and installed without issue. I restored from Back Up and everything was in place. No errors.
    If you are updating, try using Restore instead.

  • Hi there can you help with this error code Oxc5d1281

    I refilled the HP cartridges in my Photosmart C 7250 All-in-One and put them in and got this error.  I have D/C power,etc and it still comes up with this error code.  Now what?
    Cheers,
    British_eh

    Hi british_eh
    You could try resetting the printer, details here
    Note though that the reliability of refills tends not be as good as originals, links below FYI.....
    http://h10025.www1.hp.com/ewfrf/wc/document?docname=c00853819&cc=us&dlc=en&lc=en&jumpid=reg_R1002_US...
    http://www.qualitylogic.com/2009HPinktest.pdf
    Kind Regards, Ciara
    Although I am an HP employee, I am speaking for myself and not for HP.
    Twitter: @Ciara_B_HP

  • Need help with pie chart code

    I am new to Java and am having problems and I am in need of some help. I have written the code for my Mortgage Calculator but do not know how to get my chart to work. I found an example of the chart code in my text book but I am not sure if I wrote it wrong. When I run the MortCalc code it compiles but the Pie Chart code won't. I tried to run the chart code by itself but it prints out another calculator. My question is 1.) Is my chart code written wrong? and 2.) How do i enter it into my MortCalc code so that I get my chart?
    **Below I have included the assignment(so you know what I am doing exactly) and below that the pie chart code just in case you have questions. Thanks for any advice you can give.
    **If you need the rest of the code I can post it too. It was too long to post with the pie chart code.
    Assignment:
    Write the program in Java(w/ a GUI) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage adn the user's selection from a menu of availible mortgage loans:
    --7 yrs @ 5.35%
    --15 yrs @ 5.5%
    --30 yrs @ 5.75%
    Use an array for the mortgage data for the different loans. Read the interst rates to fill the array from a sequential file. Display the mortgage payment amount followed by the loan balance and interest paid for each payment over the term of the loan. Add graphics in the form of a chart.Allow the user to loop back and enter a new amount and make a new selection of quit. Please insert comments in the program to document the program.
    CODE:
    import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    //Class to hold a value for a slice
    public class PieValue {
    double value;
    Color color;
    public PieValue(double value, Color color) {
    this.value = value;
    this.color = color;
    // slices is an array of values that represent the size of each slice.
    public void drawPie(Graphics2D g, Rectangle area, PieValue[] slices) {
    // Get total value of all slices
    double total = 0.0D;
    for (int i=0; i<slices.length; i++) {
    total += slices.value;
    // Draw each pie slice
    double curValue = 0.0D;
    int startAngle = 0;
    for (int i=0; i<slices.length; i++) {
    // Compute the start and stop angles
    startAngle = (int)(curValue * 360 / total);
    int arcAngle = (int)(slices[i].value * 360 / total);
    // Ensure that rounding errors do not leave a gap between the first and last slice
    if (i == slices.length-1) {
    arcAngle = 360 - startAngle;
    // Set the color and draw a filled arc
    g.setColor(slices[i].color);
    g.fillArc(area.x, area.y, area.width, area.height, startAngle, arcAngle);
    curValue += slices[i].value;

    // Draw each pie slice
    double curValue = 0.0D;
    int startAngle = 0;
    for (int i=0; i<slices.length; i+) {
    // Compute the start and stop angles
    startAngle = (int)(curValue 360 / total);
    int arcAngle = (int)(slices.value * 360 / total);Look here and i think you will find some syntax errors.
    Count the brackets.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for