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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -