-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 に答える