-1

我有网络服务,我正在从网络服务获取数据并将该数据存储到数据库中,但是我给出了异常,我已经检查了我的数据库是否在设备上成功创建并且我正在正确关闭我的数据库成功打开我认为它是我的网络服务数据中的特殊字符问题,我的网络服务中有一些故事,并且包含一些特殊字符......,当我尝试将它们插入我的数据库时,他们给出 SQL LOGIC ERROR try{ conn = (StreamConnection) Connector.open(" http://tandonindia.com/story_new_xml?user=500 "+";deviceside=true"/ +";interface=wifi" /);

            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();  
            docBuilderFactory.setIgnoringElementContentWhitespace(true);
            docBuilderFactory.setCoalescing(true);

            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();    

            docBuilder.isValidating();      

            is = conn.openInputStream();    
            doc = docBuilder.parse(is);     
            doc.getDocumentElement().normalize(); 
            System.out.println ("ROOT ELEMENT OF DOCUMENT IS=  " +  doc.getDocumentElement().getNodeName());
            //add(new LabelField(""+  doc.getDocumentElement().getNodeName()));

            NodeList nodeList = doc.getElementsByTagName("item");
            for (int i = 0; i < nodeList.getLength(); i++){
                //System.out.println(""+nodeList.getLength());

                Node node = nodeList.item(i);
                if(node.getNodeType() == Node.ELEMENT_NODE) {

                      Element element = (Element) node;
                      NodeList nodelist = element.getElementsByTagName("Week");
                      Element element1 = (Element) nodelist.item(0);
                      NodeList fstNm = element1.getChildNodes();
                      System.out.print("Week-- " + (fstNm.item(0)).getNodeValue().toString());

                      Element element2 = (Element) node;
                      NodeList nodelist1 = element2.getElementsByTagName("Year");
                      Element element3 = (Element) nodelist1.item(0);
                      NodeList fstNm1 = element3.getChildNodes();
                      System.out.println("\nYear-- "+(fstNm1.item(0)).getNodeValue().toString());


                      //For retriving text from node notification
                      Element element4 = (Element) node;
                      NodeList nodelist2 = element4.getElementsByTagName("subject");
                      Element element5 = (Element) nodelist2.item(0);
                      NodeList fstNm2 = element5.getChildNodes();
                      System.out.println("subject--"  + (fstNm2.item(0)).getNodeValue().toString());


                      //For retriving text from node Link
                      Element element15 = (Element) node;
                      NodeList nodelist21 = element15.getElementsByTagName("storypath");
                      Element element51 = (Element) nodelist21.item(0);
                      NodeList fstNm22 = element51.getChildNodes();
                      System.out.println("storypath--"  + (fstNm22.item(0)).getNodeValue().toString());

                      try {
                            db2 = DatabaseFactory.open(str);
                             db2.beginTransaction();
                             Statement statmnt2 = db2.createStatement("INSERT into tbstory(Week,Year,subject,storypath) VALUES("+"'"+(fstNm.item(0)).getNodeValue().toString()+"','"+(fstNm1.item(0)).getNodeValue().toString()+"','"+(fstNm2.item(0)).getNodeValue().toString()+"','"+(fstNm22.item(0)).getNodeValue().toString()+"')");
                             System.out.println("INSERTING STORYIESSSSSSSSSSSSSSSSS");

                             statmnt2.prepare();
                             statmnt2.execute();
                             statmnt2.close();

                             db2.commitTransaction();
                             db2.close();
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            db2.close();
                            System.out.println("1111222333"+e.toString());

                            e.printStackTrace();
                        }

                }

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

        }catch(Exception e){

            System.out.println("error 1"+e.getMessage());
        }

我得到的错误低于 net.rim.device.api.database.DatabaseException: INSERT into tbstory(Week,Year,subject,story[0.0] path) VALUES('25','2013','PRIZE VEGETABLE!' ,'Baba 将这个故事告诉了 Kodaikanal 的学生。


  now this time i have very less content , again i got the error on INSERT query and how can i find that which character is giving me error, i'll post my exception while adding a small string in my Database.. can u tell me according to you which character is giving  error  or how can i figure out  which character is giving me error

net.rim.device.api.database.DatabaseException: INSERT into tbstory(storypath) VALUES('O[0.0] ne day, the Pandit came excitedly and told Rabidas, a cobbler, "My friend Today the queen is coming [0.0] to have the holy bath. I have been called to do the rit[0.0] uals; for today is a very special day, whoever has a dip in mother Ganga could emerge all pure. Do C[0.0] ome Don't miss this opportunity" Rabidas shook his head and said "Man changa to katooti me Ganga", p[0.0] ointing to his leather bag, (if mind is pure Ganga will[0.0]  be in my leather bag).
[0.0] 
[0.0]  
[0.0] 
[0.0] Angrily the Pandit went away muttering, "When will this fool understand the truth and try to earn Go[0.0] d's Grace?"  His life will be spent in the company of  this disgusting leather only'.
[0.0] 
[0.0]  
[0.0] 
[0.0] In the evening the Pandit came panting, "Rabi, What a miracle occurred today  Ganga Mayya Blessed ou[0.0] r queen with a golden bangle and told her she will get the second one when a person as pure and as d[0.0] evoted as she come to there to dip in the holy river. T[0.0] omorrow the whole city of Kashi will come and see who that lucky Blessed person is".
[0.0] 
[0.0]  
[0.0] 
[0.0] Rabi said "My dear friend It must be you only; for who can be more purer and devoted than you who ta[0.0] ke hundreds of people for holy bath every day?"
[0.0] 
[0.0]  
[0.0] 
[0.0] Pleased and puffed up with pride the Pandit said, "I know it must be me only. Tomorrow I will be the[0.0]  first person to take the holy dip".
[0.0] 
[0.0]  
[0.0] 
[0.0] Next day, the Pundit came late in the evening with an air of dejection over him. Rabi asked "So, my [0.0] friend did you get the second bangle?
[0.0] 
[0.0]  
[0.0] 
[0.0] Rabi closed his eyes and silently prayed "Oh mother, why don't you save this poor Pundit from this d[0.0] ilemma? I know you are everywhere and  manifest anything at any time. Then he put his hand into his [0.0] leather bag and Lo Wonder  of wonders A shinning gold b[0.0] angle emerged
[0.0] 
[0.0]  
[0.0] 
[0.0] The Pandit was spellbound at this great miracle. He bowed down to the cobbler in all humility.
[0.0] 
[0.0]  
[0.0] 
[0.0] "My dear, you have opened my eyes. All work is worship of God; Inner Purity is greater than Outer Pu[0.0] rity.'): SQL logic error or missing database
4

2 回答 2

1

为避免此类格式问题或SQL 注入攻击,您不应将字符串直接嵌入 SQL 语句中,而应始终使用参数:

Statement statmnt2 = db2.createStatement(
    "INSERT INTO tbstory(Week,Year,subject,storypath) VALUES(?,?,?,?)");
statmnt2.prepare();
statmnt2.bind(1, fstNm.item(0).getNodeValue().toString());
statmnt2.bind(2, fstNm1.item(0).getNodeValue().toString());
statmnt2.bind(3, fstNm2.item(0).getNodeValue().toString());
statmnt2.bind(4, fstNm22.item(0).getNodeValue().toString());
statmnt2.execute();
statmnt2.close();
于 2013-06-29T10:41:01.420 回答
1

您正在测试哪个版本的 BBOS?我发现当您尝试使用事务时,OS 5 的早期版本会抛出“Sql 逻辑错误”异常。唯一的解决方法是切换到隐式事务 - 只需跳过对 beginTransaction/commitTransaction 的调用。这会影响 5.0.0.0 和 5.0.0.400 以及 5.0.0.402、5.0.0.405、5.0.0.602 之间的所有 BBOS 应用程序版本。

于 2013-06-30T00:12:58.237 回答