Wywoływanie metody w pętli.

0
 
					LinkedList<Integer>	listOfPizzaId = new LinkedList<Integer>();
					
					for(int i = 0; i <table.getModel().getRowCount(); i++){
						String name = table.getModel().getValueAt(i, 0).toString();
						double size = (double)(table.getModel().getValueAt(i, 2));
						System.out.println("Nazwa: " + name + " " +size);
						int id = conn.loadTest(name, size);
						//cały czas zwraca 0
						//więc nie będę mogł wstawić do później do zawartość zamówienia bo nie ma pizzy o id 0
						JOptionPane.showMessageDialog(null, id);
					}

Kod metody:
Próbuję pobrać idpizzy z bazy, ale metoda cały czas zwraca 0.

	public int loadTest(String name, double srednica) {
		String sql = "SELECT IDPIZZY, SREDNICA FROM PIZZE WHERE NAZWA = '"+name+"' and SREDNICA ="+srednica;
		int id = 0;
		try {
			ResultSet result = statement.executeQuery(sql);
			while (result.next()) {
				id = result.getInt("IDPIZZY");
			}
			return id;
		} catch (SQLException ex) {
			JOptionPane.showMessageDialog(null,
					"Problem z pobraniem IDID danych pizzy.\n" + ex.getMessage());
			return id;
		}
	}

A teraz tutaj:

		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Connection conn = new Connection();
				conn.openConnection();
				String test = "Ryba";
				double size = 42;
				int id = conn.loadTest(test, size);
				JOptionPane.showMessageDialog(null, id);
			}
		});

Teraz metoda mi zwraca bez problemu id tej pizzy, więc jest na pewno dobra. Może ktoś ma jakiś pomysł w czym problem?

1

A co wyświetla to polecenie

System.out.println("Nazwa: " + name + " " +size);
0

Wkradł się głupi błąd z jtable brałem cenę zamiast rozmiaru pizzy i dlatego metoda cały czas zwracała 0, bo nie było pizzy w bazie o takim rozmiarze.

1 użytkowników online, w tym zalogowanych: 0, gości: 1