This is the code of my data base that its giving this error java.sql.SQLException: Parameter index out of range 1 > number of parameters, which is 0And I'm going to put the code of what I need to save on my database:PedidoDTO nuevoPedido = new PedidoDTO();nuevoPedido.setFolio("323423"); nuevoPedido.setFecha(new Date());nuevoPedido.addDetalle(detalle1); nuevoPedido.addDetalle(detalle2); nuevoPedido.addDetalle(detalle3); long pedidoId =dao.guardar(nuevoPedido); System.out.println( "ID del nuevo pedido: " + pedidoId );public long guardar(PedidoDTO obj) throws SQLException { PedidoDTO dto = new PedidoDTO(); String url="jdbc:mysql://127.0.0.1:3306/capacitacion?user=capacitacion&password=password"; try { System.out.println("Hola"); Connection con = DriverManager.getConnection(url); String sentenciaSQL = "INSERT INTO capacitacion .pedido (fecha, total, folio) VALUES (" + obj.getFecha() + ", " + obj.getTotal() + ", " + obj.getFolio() + ")"; PreparedStatement s = con.prepareStatement(sentenciaSQL); //s.setInt(1, obj.getId()); s.setLong(1, obj.getFecha()); s.setDouble(2, obj.getTotal()); s.setString(3, obj.getFolio()); s.execute(); for(PedidoDetalleDTO detalle:obj.getPedidoDetalle()){ dto.getId(); dto.getFecha(); dto.getTotal(); dto.getFolio(); }con.close(); } catch (SQLException e) { System.out.println(e); } return dto.getId();} 解决方案 VALUES (" + obj.getFecha() + ", " + obj.getTotal() + ", " + obj.getFolio() + ")should beVALUES (?,?,?)When you use preparedstatement, you will set values using s.set...(..)Read this tutorial on how to use preparedstatements 这篇关于连接到数据库的Java列表是否超出参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-30 13:50