3
I am doing a work on Java Web ticket sales system and I have a question in my code to bring this data example: In select I consult 3 fields of my table: origin, destination and date the problem that is not bringing any data, has been tested directly at the bank and I function.
Practical Example:
- RIO DE JANEIRO - SÃO PAULO - 08/20/2015
- RIO DE JANEIRO - SÃO PAULO - 23/08/2015
- RIO DE JANEIRO - SANTA CATARINA - 20/08/2015
I consult this data by a form and then play in a table. SQLFIDLE of my table: http://sqlfiddle.com/#! 9/478f3/1
Consultation:
public ArrayList<Passagem> consultar(Passagem p) {
try {
Connection conexao = getConexao();
PreparedStatement pstm = conexao.prepareStatement(
"Select * from passagem where " +
"origem = ? " +
"AND destino = ? " +
"AND data = ?");
pstm.setString(1, p.getOrigem());
pstm.setString(2, p.getDestino());
pstm.setString(3, p.getData());
ResultSet rs = pstm.executeQuery();
ArrayList<Passagem> listaPassagens = new ArrayList<Passagem>();
while (rs.next()) {
p.setIdpassagem(rs.getInt("idpassagem"));
p.setOrigem(rs.getString("origem"));
p.setDestino(rs.getString("destino"));
p.setData(rs.getString("data"));
p.setPartida(rs.getString("partida"));
p.setChegada(rs.getString("chegada"));
p.setValor(rs.getInt("valor"));
listaPassagens.add(p);
}
pstm.close();
conexao.close();
} catch (Exception e) {
e.printStackTrace();
}
return listaPassagens;
}
Table of the Database:
CREATE TABLE passagem(
idpassagem NUMBER(5,0),
origem VARCHAR2(50),
destino VARCHAR2(50),
data VARCHAR2(255),
partida VARCHAR2(255),
chegada VARCHAR2(255),
valor NUMBER(8,2),
PRIMARY KEY(idpassagem)
);
Form I search the data:
<form action="passagem.jsp" method="post">
Cidade Origem:
<input type="text" name="origem">
<br>
<br>
Cidade Destino:
<input type="text" name="destino">
<br>
<br>
Data:
<input type="text" id="datepicker" name="data" >
<br>
<br>
<input type="submit" value="busca"/>
</form>
Where I receive the data and show in a table:
<body>
<form method="post" action="AdicionarCarrinho.jsp">
<table border="1">
<th>Selecione Passagem</th>
<th>Cidade Origem</th>
<th>Cidade Destino</th>
<th>Data</th>
<th>Partida</th>
<th>Chegada</th>
<th>Preço(R$)</th>
<th>Id Onibus</th>
<th>Quantidade</th>
<%
PassagemDAO pdao = new PassagemDAO();
Passagem p = new Passagem();
if(request.getParameter("origem") != null && request.getParameter("destino") != null
&& request.getParameter("data") != null){
p.setOrigem(request.getParameter("origem"));
p.setDestino(request.getParameter("destino"));
p.setData(request.getParameter("data"));
ArrayList<Passagem> lista = pdao.consultar(p);
for(Passagem p2 : lista){
%>
<tr>
<td align="center"> <input type="checkbox" name="comprar_ <%= p2.getIdpassagem() %>" value="Sim"> </td>
<td> <%= p2.getOrigem() %> </td>
<td> <%= p2.getDestino() %> </td>
<td> <%= p2.getData() %>" </td>
<td> <%= p2.getPartida() %> </td>
<td> <%= p2.getChegada() %> </td>
<td> <%= p2.getValor() %></td>
<td> <%= p2.getIdonibus() %> </td>
<td align="center"> <input type="text" name="quantidade_<%= p2.getIdpassagem() %>" size="1" maxlength="3" value="1"> </td>
</tr>
<%
}
}
%>
<p> <input type="submit" value="Adicionar ao Carrinho" name="Submit">
<input type="reset" name="Limpar" value="Limpar"> </p>
</table>
</form>
</body>
The problem now that it does not return any data as it was said, is giving this error:
Warning: The web application [/highway] Registered the JDBC driver [oracle.jdbc.driver.Oracledriver] but failed to unregister it when the web application was stopped. To Prevent a memory Leak, the JDBC Driver has been forcibly unregistered.
I am using netbeans with Glafissh server and Oracle database. In detail of the date is in String, when I refer use the form up there that step a type="text" use the datepicker of Jquery, making the separate queries works normal, the problem is to do together: returns blank and in the glafish log of the above error, if anyone has any solution to this problem.
did not understand the question... what you want to return from the query ?
– Pedro Laini
I couldn’t understand anything, what you want her to
query
return?– Jéf Bueno
I have a form, I do the search for Origin City, Destination City and Data, my query makes the search, however it is bringing the independent data, needed to bring the researched specific data.
– Rafilds
What do you mean by dice independent?
– Jéf Bueno
Let me get this straight, you want to type in yours form one city of origin, one destination city and a date and bring only one of the records you have in your database?
– Jéf Bueno
rephrase the question
– Pedro Laini
Even the example up there, I researched a ticket from São Paulo to Rio de Janeiro with date 20/08/15, right? , would have to bring only this data, but is bringing others, which has as its origin city 'São Paulo', etc..
– Rafilds
Yes I have a database table with this data, need to consult and shows.
– Rafilds
@Rafilds, edit the question and put these details that you spoke in the comments, otherwise all information is dispersed.
– Jéf Bueno
@Rafilds, is returning some error or simply does not bring any results?
– Jéf Bueno
has already been edited up there, is returning 1 error and the blank query.
– Rafilds