Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners More than 1 preparedStatement object
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Kriti
More than 1 preparedStatement object
1 Answer(s)      5 years and 7 months ago
Posted in : Java Beginners



Advertisement
View Answers

June 2, 2009 at 12:10 PM


Hi Friend,

You can use more than one prepared Statement object in the java class.Try the following code:

import java.sql.*;

public class JdbcPreparedstatementAddbatch {

public static void main(String args[]) {

Connection con = null;
PreparedStatement pst1 = null;
PreparedStatement pst2 = null;

String url = "jdbc:mysql://localhost:3306/";;
String db = "mysql";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";

try {

Class.forName(driver);
con = DriverManager.getConnection(url + db, user, pass);
pst1 = con.prepareStatement("update data set address=? where name =?");


pst1.setString(1, "Delhi");
pst1.setString(2, "angelina1");
pst1.addBatch();

pst1.setString(1, "Mumbai");
pst1.setString(2, "angelina2");
pst1.addBatch();

pst1.executeBatch();
pst1.close();
pst2 = con.prepareStatement("update data set address=? where name =?");


pst2.setString(1, "Agra");
pst2.setString(2, "AAAAA");
pst2.addBatch();

pst2.setString(1, "Chennai");
pst2.setString(2, "BBBBB");
pst2.addBatch();

pst2.executeBatch();
pst2.close();
con.close();

} catch (Exception e) {
e.printStackTrace();
}
}
}
Here we have taken two fields name and address of varchar type in the database table. We have used following methods.

1) set String ( ) - This method is used to set the value as string in place of question mark place holder.
2) addBatch ( ) - This method is used to add a set of parameter to the batch of command to this sql server prepared object.

3) execute Batch ( ) - This method is used to submit a set of command in sql query to the database, In case all the commands successfully, return you an array update count.

Thanks


Related Tutorials/Questions & Answers:
More than 1 preparedStatement object - Java Beginners
More than 1 preparedStatement object  Hey but I want to use more than one prepared Statement object using batch update.. Explain with a code using java... Thanks  Hi Friend, You can use more than one prepared
How to write more than 65536 rows in single excel file but more than 1 sheets?
How to write more than 65536 rows in single excel file but more than 1 sheets... but more than 1 sheets.. now i can write only less than 65536 rows.. but in my office db having more than 1 crore data.. pls help me... here is my code.. public class
Advertisements
PreparedStatement
PreparedStatement  What is PreparedStatement? Give me example
More than one Faces Configuration file
More than one Faces Configuration file  Is it possible to have more than one Faces Configuration file
Can a Class extend more than one Class?
Can a Class extend more than one Class?   Hi, Can a Class extend more than one Class? thanks
Apply more than one xsl for single XML
Apply more than one xsl for single XML  How to apply more than one xsl for same xml file
more than one struts-config.xml file
more than one struts-config.xml file  Can we have more than one struts-config.xml file for a single Struts application
Implementing more than one Job Details and Triggers
Implementing more than one Job Details and Triggers... will learn how to implement more than one triggers and jobs with a quartz... of more than one job details and triggers. Description of program: Here, we
for writting java program why we are taking more than one class
for writting java program why we are taking more than one class  for writting java program only one class is enough but why we are taking more than one class
problem in sending more than 500 values to a jsp page
problem in sending more than 500 values to a jsp page  when i am trying to send more than 500 values from a html form to a jsp page browser is showing that server is not sending any data...I have configured tomcat5.5
mapping between java class and more than 2 tables
mapping between java class and more than 2 tables  Association mapping of table in hibernate   Hi Friend, Please visit the following link: Hibernate Tutorial Thanks
how to handle action events in case of more than one JFrame
how to handle action events in case of more than one JFrame   I have... contains three java files namely 1. Engine.java 2. Snake.java 3. Gameoard.java when i... 1. PlayGame.java RulesDialog.java PlayGame.java has three JButtons :- Play
Deployment on Server that can be used simultaneously by more than one user
Deployment on Server that can be used simultaneously by more than one user  Sir, I have deployed my web application developed using JSP & sevlet. how could i access it on the network using xp os. I have deployed it on Tomcat
How to get more than one value from ajax
How to get more than one value from ajax  I have multiple select list box in php. i filled the value using ajax. how to get different value to fill the same list box Ex. option value as id option name as some string
Writing more than one cards in a WML deck.
   Writing more than one cards in a deck.In this lesson
How to Display Duplicate elements from more than one List in java?
How to Display Duplicate elements from more than one List in java?  How to Display Duplicate elements from more than one List in java? //I mean common elements from two List? Ex: List a1=new ArrayList(); a1.add(50
Hi.. how to write more than one sheets in a excel file... pls anybody help me....
Hi.. how to write more than one sheets in a excel file... pls anybody help me... more than one sheets.. For example: first sheet have complete mean automatically... "+tableName+" having more than 65536 rows"); System.out.println
Server side validation on dynamically generated fields from more than one table on spring framework.
Server side validation on dynamically generated fields from more than one table on spring framework.   Server side validation on dynamically generated fields from more than one table in spring mvc framework
can i restrict a class that it will not allows create more than two objects - Java Interview Questions
can i restrict a class that it will not allows create more than two objects  hi all, can i restrict a class that it will not allows create more than two objects can any help me please. Thaks bala k
J query event for selecting the more than one div in tablet browser(Select and drag)?
J query event for selecting the more than one div in tablet browser(Select and drag)?  Web application five div is created. For selecting the more... to select the more than one tag using the touch and drag event
To get the value of more than one text box in an HTML page to a jsp page - JSP-Interview Questions
To get the value of more than one text box in an HTML page to a jsp page  An html file has a text box as To get the value of this text box in a JSP... will have a name-value pair attribute. JSP has a built in object request
Use of "|" separator for selecting more than one path
Use of  "|" separator for selecting more than one path.... It allows you more flexibility by allowing you to execute multiple expressions...;information>   <person id="1">
how to restrict user against marking same event more than one times - JSP-Servlet
how to restrict user against marking same event more than one times  Hi I am developing student feedback system for educational institution. Main purpose about this application is to evaluate performance of faculty. Each
Error in connecting to the mySQL database in TOMCAT using more than one PC (database connection pooling)
Error in connecting to the mySQL database in TOMCAT using more than one PC (database connection pooling)  how do i implement connection pooling... me? I tried using DriverManager.getConnection, and I can work with two or more
how can retrieve more than one values in text field using ajax?
how can retrieve more than one values in text field using ajax?  im using php and ajax. Problem is that i want to search seat numbers bases of batch and semester condition on onchange event eg. if i search batch 2008 and semester
PreparedStatement using batch update - Java Beginners
PreparedStatement using batch update  How to execute different preparedStatement object using batch update(Java) Pls explain with the code... object.i want to use more than one..can i do
select with preparedstatement in java
select with preparedstatement in java  How to write code example for select with preparedstatement in java? Thanks   Hi, Following code examples can be used: PreparedStatement pstmt = conn.prepareStatement
why java ignore backspace event when there are more then 1 keychar for a single keystroke.
why java ignore backspace event when there are more then 1 keychar for a single keystroke.  why java ignore backspace event when there are more then 1 keychar for a single keystroke. Assume that i have a text field to get
Inserting a row using PreparedStatement
INSERING A ROW USING PREPAREDSTATEMENT If you want to execute a statement many time , "PreparedStatement " reduces execution time. Unlike a "Statement" object ,it is given an 'Sql' statement when
PHP Date add 1 year
Adding 1 year to a php date object is sometimes useful to solve some... to add 1 year easily. The code given below will show how you can add 1 year in php program. <?php //Example to add 1 year to a date object
Prepared Statement Set Object
should use PreparedStatement object as it reduces the execution time. PreparedStatement object is faster than the Statement object...: prepareStatement(String sql): This method returns the PreparedStatement object for sending
 

 

 

DMCA.com