[英]SQLITE_ERROR SQL error or missing database (near “VALUES”: syntax error)
I have the following code, and it gives me this error. 我有以下代码,它给了我这个错误。 I need to show into the database the values transmitted through the TCP connection.
我需要向数据库显示通过TCP连接传输的值。 Help?
救命? When I comment the lines between Class.forName("org.sqlite.JDBC") and conexiune.setAutoCommit(false);
当我注释Class.forName(“ org.sqlite.JDBC”)和cubexiune.setAutoCommit(false);之间的行时 and also those in IF's from String s to conexiune.commit() it work well, it seems that the connection between client and server is ok.
而且从String到cubexiune.commit()的IF都可以正常工作,看来客户端和服务器之间的连接还可以。
This is the method run in class 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();
}
}
I also have the class for the database here: 我在这里也有数据库的类:
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();
}
}
If it helps you, this is he first part of class Server, before run(): 如果有帮助,那么这是他在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();
}
}
Can you help me figure out what's wrong? 您能帮我找出问题所在吗?
您需要在结束时右括号
INSERT INTO AvionPasageri(serie,tonaj,marca,capacitate,cnp VALUES
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.