SQLITE_ERROR SQL错误或缺少数据库(“VALUES”附近:语法错误)

时间:2017-07-01 11:45:42

标签: java sqlite tcp

我有以下代码,它给了我这个错误。我需要向数据库显示通过TCP连接传输的值。救命? 当我评论Class.forName(“org.sqlite.JDBC”)和conexiune.setAutoCommit(false)之间的界限时;而且从IF到conexiune.com()的IF中的那些工作得很好,似乎客户端和服务器之间的连接是可以的。

这是在Server类中运行的方法:

public void run() {
        while(true)
        {
            try 
            {

                soc=server.accept();
                System.out.println("OK!");
                ObjectInputStream ois=new ObjectInputStream(soc.getInputStream()); 

                Class.forName("org.sqlite.JDBC"); 
                Connection conexiune=DriverManager.getConnection("jdbc:sqlite:BazaDeDate.db");
                System.out.println("Conexiunea la baza de date s-a realizat cu succes!"); 
                Statement comanda=(Statement) conexiune.createStatement(); 
                conexiune.setAutoCommit(false);


                Object obj=ois.readObject(); 
                if(obj instanceof AvionPasageri)
                {
                    AvionPasageri ap=(AvionPasageri)obj; 
                    System.out.println(ap.toString());
                    String s=""; 

                    for(String sir : ap.getCnpPasageri())
                    {
                        s+=sir;
                    }
                    ((java.sql.Statement) comanda).executeUpdate("INSERT INTO AvionPasageri(serie,tonaj,marca,capacitate,cnp VALUES(' "
                            +ap.getSerie()+"', '"+ap.getTonaj()+"', '"+ap.getMarca()+"', '"+ap.getCapacitate()
                            +"', '"+s+"')");
                    System.out.println("Inserat!");
                    conexiune.commit(); 

                }
                else if(obj instanceof AvionCargo)
                {

                    AvionCargo ac=(AvionCargo)obj; 
                    System.out.println(ac.toString());
                    String s=""; 

                    for(String sir: ac.getSerieMarfuri())
                    {
                        s+=sir;
                    }
                    ((java.sql.Statement) comanda).executeUpdate("INSERT INTO AvionPasageri(serie,tonaj,marca,capacitate,serii VALUES('"
                            +ac.getSerie()+"', '"+ac.getTonaj()+"', '"+ac.getMarca()+"', '"+ac.getCapacitate()
                            +"', '"+s+"')");
                    System.out.println("Inserat!");
                    conexiune.commit(); 
                }

                conexiune.close(); 
                soc.close();


            } catch (IOException e) {

                e.printStackTrace();
            } catch (ClassNotFoundException e) {

                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            } 

        }

我在这里也有数据库的类:

public class CreareBazaDeDate 
{

    public static void main(String[] args) throws ClassNotFoundException, SQLException
    {
    Class.forName("org.sqlite.JDBC");

    Connection conexiune=DriverManager.getConnection("jdbc:sqlite:BazaDeDate.db");

    Statement comanda=(Statement) conexiune.createStatement();

    conexiune.setAutoCommit(false);
    ((java.sql.Statement) comanda).executeUpdate("CREATE TABLE AvionPasageri( serie string, tonaj float, marca string, capacitate float, cnp string)");
    ((java.sql.Statement) comanda).executeUpdate("CREATE TABLE AvionCargo( serie string, tonaj float, marca string, capacitate float, marfa string)");

    conexiune.commit();
    conexiune.close();
    }
}

如果它对你有帮助,那么在run()之前,这是他在类Server的第一部分:

public class Server implements Runnable
{
    public ServerSocket server;
    public Socket soc;

    public static void main(String[] args) 
    {
        Thread t=new Thread(new Server());
        t.start();
    }

    public Server()
    {
        try
        {
            server=new ServerSocket(5200);
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

你能帮我弄清楚出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

你需要在

中拥有一个关闭权限
INSERT INTO AvionPasageri(serie,tonaj,marca,capacitate,cnp VALUES