Guest User

Untitled

a guest
Mar 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. Exception in thread "main"
  2. com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error
  3. in your SQL syntax; check the manual that corresponds to your MariaDB server
  4. version for the right syntax to use near '?,?,?,?)' at line 1
  5. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  6. at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  7. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  8. at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  9. at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
  10. at com.mysql.jdbc.Util.getInstance(Util.java:386)
  11. at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
  12. at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
  13. at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
  14. at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
  15. at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
  16. at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2788)
  17. at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2738)
  18. at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:899)
  19. at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:737)
  20. at inventario.SwitchInt.RegistrarProducto(SwitchInt.java:59)
  21. at inventario.Inventario.main(Inventario.java:31)
  22.  
  23. Connection conexion = null;
  24. Statement comando = null;
  25. ResultSet registro;
  26.  
  27. public Connection MySQLConnect() {
  28.  
  29. try {
  30. Class.forName("com.mysql.jdbc.Driver");
  31. String servidor = "jdbc:mysql://localhost:3306/inventario";
  32. String usuario = "root";
  33. String pass = "";
  34. conexion = DriverManager.getConnection(servidor, usuario, pass);
  35.  
  36. } catch (ClassNotFoundException ex) {
  37. JOptionPane.showMessageDialog(null, ex, "Error en la conexión a la base de datos: " + ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  38. conexion = null;
  39. } catch (SQLException ex) {
  40. JOptionPane.showMessageDialog(null, ex, "Error en la conexión a la base de datos: " + ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  41. conexion = null;
  42. } catch (Exception ex) {
  43. JOptionPane.showMessageDialog(null, ex, "Error en la conexión a la base de datos: " + ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  44. conexion = null;
  45. } finally {
  46. JOptionPane.showMessageDialog(null, "Conexion establecida correctamente.");
  47. return conexion;
  48. }
  49. }
  50.  
  51. PreparedStatement prepareStatement(String insert_into_usuarioNombreApellidosEdadCor) {
  52. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  53. }
  54. }
  55.  
  56. public class SwitchInt {
  57.  
  58. **Conexion db = new Conexion();
  59. Connection cn = db.MySQLConnect();**
  60.  
  61.  
  62. static String nombre;
  63. static double precio;
  64. static int opcion, stock, codigo;
  65. Producto p;
  66. Vector<Producto> productos = new Vector<Producto>();
  67.  
  68. public void Intro() {
  69. System.out.print("nElija un número:n 1. Registrar producton 2. Vender producton 3. Buscar producton 4. Calcular precio medion 5. Salir nn ");
  70. }
  71.  
  72. public void RegistrarProducto() throws SQLException {
  73. System.out.print("n Ingrese un código del producto: n");
  74. codigo = entrada.nextInt();
  75. System.out.print("Nombre: ");
  76. nombre = entrada.next();
  77. System.out.print("Precio: ");
  78. precio = entrada.nextDouble();
  79. System.out.print("Stock: ");
  80. stock = entrada.nextInt();
  81. p = busqueda(codigo, productos);
  82.  
  83. if (p == null) {
  84. productos.addElement(new Producto(codigo, nombre, precio, stock));
  85.  
  86. **String sql = "INSERT INTO productos (ID, Nombre, Precio, Stock) VALUES(?,?,?,?)";
  87.  
  88. PreparedStatement pst;
  89. pst = cn.prepareStatement(sql);
  90. pst.setInt(1, codigo);
  91. pst.setString(2, nombre);
  92. pst.setDouble(3, precio);
  93. pst.setInt(4, stock);
  94. pst.execute(sql);**
  95.  
  96. System.out.print("Producto agregadon");
  97. } else {
  98. System.out.print("ya existe este producto");
  99. }
  100. }
Add Comment
Please, Sign In to add comment