java - Is it correct to use CallableStatement in JSF -


i'm still learning jsf in past created project using swing jdbc , mysql rdbms. right i'm working on web project become more familiar jsf.

most of examples saw online used preparedstatement , haven't seen used callablestatement

i asked because think i'll need use sql transactions perform tasks. so, callablestatement me , used callablestatement in past.

also, noticed in examples saw, never used try-with-resources syntax has auto-closing of resources

consider method below.

public void register() throws sqlexception{         string myfirstname = this.getfirstname();         string mylastname = this.getlastname();         string mymiddlename = this.getmiddlename();         string myemail = this.getemail();         try{             context context = new initialcontext();             datasource = (datasource)context.lookup("java:comp/env/jdbc/mydb");         }catch(namingexception e){             e.printstacktrace();         }             if(datasource == null){                 throw new sqlexception("can't datasource");             }          connection connection = datasource.getconnection();             if(connection == null){                  throw new sqlexception("unable connect datasource");              }          try{             string sql = "insert customer (firstname,lastname,middlename,email) values(?,?,?,?)";             preparedstatement addcustomer = connection.preparestatement(sql);                 addcustomer.setstring(1, myfirstname);                 addcustomer.setstring(2, mylastname);                 addcustomer.setstring(3, mymiddlename);                 addcustomer.setstring(4, myemail);          }finally{             connection.close();         }      } 

is possible me replace preparedstatement addcustomer = connection.preparestatement(sql);

string sql = "{call addcustomer (?,?,?,?)}"; callablestatement = conn.preparecall(sql); 

if not, best solution make use of sql transactions contained in stored procedures in jsf

i'd appreciate example best help.

thank you.


Comments

Popular posts from this blog

Formatting string according to pattern without regex in php -

c - zlib and gdi32 with OpenSSL? -

java - inputmismatch exception -