create table from java that has a database in access

1

I would like a table, when I want it to increase again from 1, but I searched in many places and this can not be done from java ... although if someone knows it would be great, if they could help me. Then going back to the topic, as an alternative to this, they advise creating a table with the same fields and eliminating the other one. but you do not want to create the table from neatbeans. this error comes out As you can see it says that there is a parenthesis that does not wait but I have reviewed my parentheses and they are fine ... I could collaborate and see where the error is please.

    try {



                           String name="ticket2";
        String Query = "CREATE TABLE " + name + ""
                + "(id int(10) not null auto_increment,primary key (id),cod VARCHAR(50), nombre VARCHAR(50),kilox VARCHAR(50), precio VARCHAR(50),peso VARCHAR(50),total VARCHAR(50))";



                         connection=con.conexion();
                   ps=connection.prepareStatement(Query);
                   ps.execute();  
                   ps.close();


           }catch (SQLException e){
               JOptionPane.showMessageDialog(null,"Error al eliminar producto de venta,Error de sistema, comuniquese con proveedor: "+e);
           }
    
asked by anma1d 11.03.2017 в 05:04
source

1 answer

2

Try this:

try {
    String name="ticket2";
    String Query = "CREATE TABLE " + name
        + " (id Counter Primary Key,cod TEXT(50), nombre TEXT(50),kilox"              
        + " TEXT(50), precio TEXT(50),peso TEXT(50),total TEXT(50))";

    connection=con.conexion();
    ps=connection.prepareStatement(Query);
    ps.execute();  
    ps.close();
}
catch (SQLException e){
    JOptionPane.showMessageDialog(null,"Error al eliminar producto de"
    + " venta,Error de sistema, comuniquese con proveedor: "+e);
}

What happens is that you are mixing sentences used in postgres, for example, Counter is the directive to do auto-increment in access, and the one you use is used in postgres. The same with the VARCHAR data type, YOU MUST USE TEXT .

    
answered by 11.03.2017 в 13:04