2
Doing the method to select all data from a table, but is returning me error. console: Open bank.
java.sql.SQLException: No value specified for parameter 1 No value specified for parameter 1 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926) at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2176) at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2100) at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:931) at persistence.ProdutoDao.findAll(ProdutoDao.java:27) at persistence.ProdutoDao.main(ProdutoDao.java:51)
Method findAll:
public List<Produto> findAll()throws Exception{
open();//metodo q abre a conexao com o banco
stmt = con.prepareStatement(SELECT); //constante select*from produto
stmt.execute();
rs = stmt.executeQuery();
List<Produto> lista = new ArrayList<>();
while(rs.next()){
lista.add(new Produto(
rs.getInt(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getDouble(5)
)
);
}
close();//metodo que fecha a conexao com o banco
return lista;
}
public static void main(String[] args) {
try {
ProdutoDao pd = new ProdutoDao();
System.out.println(pd.findAll());
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
System.out.println("Nao listou " + e.getMessage());
}
}
Apparently the constant is wrong, she calls
INSERT
and the code looks like a select.– rray
Sorry, I just messed up with the method that comes above it, the constant is SELECT and when it comes to copying here I made the mess. String receives "select * from product;"
– Júnior Gorosh