Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exception in thread "main"
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error
- in your SQL syntax; check the manual that corresponds to your MariaDB server
- version for the right syntax to use near '?,?,?,?)' at line 1
- at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
- at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
- at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
- at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
- at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
- at com.mysql.jdbc.Util.getInstance(Util.java:386)
- at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
- at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
- at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
- at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
- at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2788)
- at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2738)
- at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:899)
- at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:737)
- at inventario.SwitchInt.RegistrarProducto(SwitchInt.java:59)
- at inventario.Inventario.main(Inventario.java:31)
- Connection conexion = null;
- Statement comando = null;
- ResultSet registro;
- public Connection MySQLConnect() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String servidor = "jdbc:mysql://localhost:3306/inventario";
- String usuario = "root";
- String pass = "";
- conexion = DriverManager.getConnection(servidor, usuario, pass);
- } catch (ClassNotFoundException ex) {
- JOptionPane.showMessageDialog(null, ex, "Error en la conexión a la base de datos: " + ex.getMessage(), JOptionPane.ERROR_MESSAGE);
- conexion = null;
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, ex, "Error en la conexión a la base de datos: " + ex.getMessage(), JOptionPane.ERROR_MESSAGE);
- conexion = null;
- } catch (Exception ex) {
- JOptionPane.showMessageDialog(null, ex, "Error en la conexión a la base de datos: " + ex.getMessage(), JOptionPane.ERROR_MESSAGE);
- conexion = null;
- } finally {
- JOptionPane.showMessageDialog(null, "Conexion establecida correctamente.");
- return conexion;
- }
- }
- PreparedStatement prepareStatement(String insert_into_usuarioNombreApellidosEdadCor) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- }
- public class SwitchInt {
- **Conexion db = new Conexion();
- Connection cn = db.MySQLConnect();**
- static String nombre;
- static double precio;
- static int opcion, stock, codigo;
- Producto p;
- Vector<Producto> productos = new Vector<Producto>();
- public void Intro() {
- System.out.print("nElija un número:n 1. Registrar producton 2. Vender producton 3. Buscar producton 4. Calcular precio medion 5. Salir nn ");
- }
- public void RegistrarProducto() throws SQLException {
- System.out.print("n Ingrese un código del producto: n");
- codigo = entrada.nextInt();
- System.out.print("Nombre: ");
- nombre = entrada.next();
- System.out.print("Precio: ");
- precio = entrada.nextDouble();
- System.out.print("Stock: ");
- stock = entrada.nextInt();
- p = busqueda(codigo, productos);
- if (p == null) {
- productos.addElement(new Producto(codigo, nombre, precio, stock));
- **String sql = "INSERT INTO productos (ID, Nombre, Precio, Stock) VALUES(?,?,?,?)";
- PreparedStatement pst;
- pst = cn.prepareStatement(sql);
- pst.setInt(1, codigo);
- pst.setString(2, nombre);
- pst.setDouble(3, precio);
- pst.setInt(4, stock);
- pst.execute(sql);**
- System.out.print("Producto agregadon");
- } else {
- System.out.print("ya existe este producto");
- }
- }
Add Comment
Please, Sign In to add comment