dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Advanced
Sep 4, 2007

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Execute a SQL Statement with Variable Parameters

When you need to execute the same SQL statement (in general an UPDATE) multiple times with different parameter values you can use the PrepareStatement method like this:

Connection conn=null;
PreparedStatement pst=null;
String[] nm=new String[3];
int[] nc=new int[3];
...
try {
nm[0]="Costescu",nm[1]="Alexandrescu",nm[2]="Popovici";
nc[0]=234423;nc[1]=123344;nc[2]=534562;

pst=conn.prepareStatement("UPDATE Table1 SET Nume=? WHERE Nr_cont=?");
     for(int i=0;i<=2;i++)
         {
         pst.setString(1,nm[i]);
         pst.setInt(2,nc[i]);
         pst.executeUpdate();
         }
     }catch (SQLException e){System.out.println(e.getMessage());}
...
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date