-1

当我尝试使用 Java 代码对 Sqlite 执行此查询时,它给了我异常:

询问:

INSERT INTO "tbl_appwidgets" VALUES (85,'2012-03-28 17:29:30','2012-03-28   17:29:30','AEBFB085','RD Filmography','','https://play.google.com/store/apps/details?  id=com.techv.filmography','R.D.Burman was a renowned Bollywood Music Director. In a prolific career spanning over 33 years, RD composed music for over 290 Hindi Films.
R.D.Burman Filmography is a tribute by www.panchammagic.org to the legendary music  composer.   It is an easy reference App that provides list of each and every Hindi movie and  its songs   for which RD composed music.',0,NULL,'0',1,0,1,'0',13000,0,51,137);

例外:

java.sql.SQLException: unrecognized token: "'R.D.Burman was a renowned Bollywood Music Director. In a prolific career spanning over 33 years, RD composed music for over 290 Hindi Films."
at org.sqlite.DB.throwex(DB.java:288)
at org.sqlite.NativeDB.prepare(Native Method)
at org.sqlite.DB.prepare(DB.java:114)
at org.sqlite.Stmt.executeUpdate(Stmt.java:102)
at ReadMySqlDump.<init>(ReadMySqlDump.java:96)
at ReadMySqlDump.main(ReadMySqlDump.java:115)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

当我从 Sqlite GUI 运行它并且该行被正确插入时,这个查询工作正常。有人可以指出原因和解决方案吗?

编辑

执行插入的 Java 代码: public class ReadMySqlDump {

static String sep = System.getProperty("line.separator");

public  ReadMySqlDump(){
    try{
        String s = "";
        String buff="";
        ArrayList<String> creates = new ArrayList<String> ();
           ArrayList<String> inserts = new ArrayList<String> ();

        boolean createStart = false;
        String currentCreate = "";

        BufferedReader br = new BufferedReader(new FileReader("mydb.sql.sql"));
        while((buff=br.readLine()) != null){
            buff = buff.trim();
             if(buff.length() == 0)continue;
            if(buff.startsWith("/*"))continue;
             if(buff.startsWith("--"))continue;
            if(createStart && buff.startsWith(");")){
             //   System.out.println("before: " + currentCreate);
                currentCreate = currentCreate.trim();
                if(currentCreate.endsWith(","))currentCreate = currentCreate.substring(0, currentCreate.length()-1);

             //currentCreate = currentCreate.substring(0, currentCreate.length()-2);
               //  System.out.println("after: " + currentCreate);
                    currentCreate += " " + buff + sep;
                createStart = false;
                System.out.println("Current create:::::::::::::::::::::"+currentCreate);
                creates.add(currentCreate);
                currentCreate = "";
                continue;
            }
            if(createStart){
                currentCreate += " " + buff +sep;
                System.out.println("Current create 3:::::::::::::::::::::"+currentCreate);
                continue;
            }
            if(!createStart && buff.startsWith("CREATE")){
                createStart = true;
                currentCreate += buff + sep;
                System.out.println("Current create 2:::::::::::::::::::::"+currentCreate);
                continue;
            }


            if(buff.startsWith("INSERT")) {
                inserts.add(buff);
                continue;

            }



        }
        br.close();

        for(String ss: creates){
            System.out.println(ss);
        }

        System.out.println("");
          System.out.println("");

                for(String ss: inserts){
            System.out.println(ss);
        }


         Class.forName("org.sqlite.JDBC");
    Connection conn = DriverManager.getConnection("jdbc:sqlite:testNew5.db");
    Statement stat = conn.createStatement();
          for(String ss: creates){

              System.out.println("SQL command: " + ss);

            stat.executeUpdate(ss);
        }

      //  ResultSet rs = stat.executeQuery("select * from tbl_passion_attributes");
        //  while(rs.next()){

         // }
        Connection conn = DriverManager.getConnection("jdbc:sqlite:testNew5.db");
        Statement stat = conn.createStatement();
                  for(String ss: inserts){

            System.out.println("ss: " + ss);
            int n =  stat.executeUpdate(ss);
            System.out.println("n: " + n);
        }
             conn.close();



    } catch(Exception ex){

        ex.printStackTrace();

    }


}

public static void main(String[] args) {

    new   ReadMySqlDump();
}

}

4

1 回答 1

1

应该是断线吧 您的实际 Java 代码是什么样的?

于 2012-12-13T06:25:14.810 回答