java - No value specified for parameter 1 -


i using hiberante connect postgres database. trying insert record database. have values record in string array got csv file. dao code

stringbuffer query=new stringbuffer("insert t_wonlist values(");         for(int i=0;i<67;i++){             query.append(values[i]+",");         }         query.deletecharat(query.lastindexof(","));         query.append(");");          sessionfactory.getcurrentsession().createsqlquery(query.tostring()).executeupdate();         system.out.println("query executed");         sessionfactory.getcurrentsession().flush(); 

i using stringbuffer, can append values query using loop.

but when execute query getting following exception

 org.postgresql.util.psqlexception: no value specified parameter 1. 

i sure number of parameters correct. can me. thanks

you're approaching in bizarre , backwards manner.

the immediate problem failure escape/quote ? in 1 of input strings, pgjdbc thinks it's query parameter. doesn't mean should fix escaping/quoting question marks, it's sign you're taking entirely wrong approach.

please read this page on sql injection , this site.

you're using hibernate orm, you'd using jpa interface or direct hibernate interface create new domain objects , persisting them. typical approach new object, use entitymanager.persist method (if using jpa) or session.save method (if using hibernate directly) persist entities.

if want use direct jdbc instead should creating jdbc preparedstatement, setting parameters, , applying it. see this tutorial. since you're loading csv you'd in jdbc batch, though doesn't gain in postgresql.

better yet, since you're importing csv can use postgresql's built-in copy command via pgjdbc's copymanager stream changes efficiently target table.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -