Home Answers Viewqa Java-Beginners More than 1 preparedStatement object

 
 


Kriti
More than 1 preparedStatement object
1 Answer(s)      4 years ago
Posted in : Java Beginners

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 Pages:
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
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
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
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">
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
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
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
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
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
PreparedStatement
PreparedStatement  What is PreparedStatement? Give me example
Retrieving Data from the table using PreparedStatement
prepareStatement() of the Connection object which will return the PreparedStatement... the executeQuery() method of the PreparedStatement object. Now the data... Retrieving Data from the table using PreparedStatement
More than one Faces Configuration file
More than one Faces Configuration file  Is it possible to have more than one Faces Configuration 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
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
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
Exceptions - More
Java NotesExceptions - More Exceptions | Exception Usage | Exceptions - More Kinds of Exceptions There are many exceptions, but they can... are usually something that should have been prevented by more careful
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
Understanding Connection Object
. An application may have one or more than one connections with a single database... the Connection object for the following things: 1). It creates the Statement... Understanding Connection Object   
Parameterized PreparedStatement Example
compiled is used every time. PreparedStatement object can also be used with SQL... .style1 { text-align: center; } Parameterized PreparedStatement Example... PreparedStatement statement=con.prepareStatement(INSERT INTO student(RollNo,Name,Course
SEND + MORE = MONEY
of magic formula is no more than 3, the number of digits of every number is no more... by exactly one space. Example Sample Input: 1 SEND + MORE = MONEY Sample Output...SEND + MORE = MONEY  Problem Description Write a program to solve
More About the CronTrigger
More About the CronTrigger       The CronTriggers are more useful than the SimpleTrigger, if we... for minutes and seconds, 0 to 31 for Day-of-Month but here, we should more
Logging Tutorial - Part 1
Logging Tutorial - Part 1 2000-12-14 The Java Specialists' Newsletter [Issue 003] - Logging part 1 Author: Dr. Heinz M. Kabutz If you are reading... are enjoying reading this information and that it will help you to be more
JDBC Insert Preparedstatement
JDBC Insert Preparedstatement     ... a connection object and this is used to built a connection between url... the same statement object many times, This reduces the time of execution to use
load more with jquery
load more with jquery  i am using jquery to loadmore "posts" from my... box its is going to display php posts and after that when i click on load more...); $('#loadmorebutton').html('Load More
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
Session Object
be saved in a Session Object ?   There is no such limit on the amount of information that can be saved in a Session Object. The only limit is the Session ID length , which should not exceed more than 4K
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 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
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
Writing more than one cards in a WML deck.
   Writing more than one cards in a deck.In this lesson
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main method and an insertWord() method. A sentence can be thought of as one or more... be at position 1, etc ?A sentence is constructed with a series of words? Index 0 1 2 3 4
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
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main method and an insertWord() method. A sentence can be thought of as one or more... be at position 1, etc ?A sentence is constructed with a series of words? Index 0
JDO UNPLUGGED - PART 1
applications become more complex. When our application needs object persistence...)       Java Data Objects is an 'Object... Hibernate from SourceForge, Object Relational Bridge(OJB) from Apache, Toplink from
bean object
in jsp page.   1)Bean.java: package form; import java.sql.*; import...; For more information, visit the following links: http://www.roseindia.net/jsp/java
Prepared Statement With Batch Update
facility. In batch update more than one records can be added in the database... in the prepareStatement method and it returns PreparedStatement object. The data...;    This section helps to use the PreparedStatement
Request Object In JSP
Request Object In JSP       This section illustrates more about the JSP implicit object called... illustrates more about the request object for parsing form data by using
Maximum Solutions - Specialists in Object Orientation
[] with the String object. If you changed the StringBuffer after calling toString...); buf.append(1); buf.append(2); // etc. buf.toString... buf = new StringBuffer(3231); buf.append(0); buf.append(1
Programming: Initials 1
than an object type. On the other hand, the substring(...) solution has... Java: Programming: Initials 1 Name... -- processing hundreds of thousands of names, it would be more efficient to use
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
New Page 1
than one parameter values for a parameter the parameterValue implicit object...} The first named variable in the expression is either an implicit object... to the pageContext object. If the first value, to the left of the dot operator is a map
Ajax request object
Ajax request object  i have to open more than one time a same jsp page with same input using Ajax.. But it will be opened only one time. i can open If i give different input.. how to solve this problem
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
Difficult Interview Questions Page -1
at this organization not more than personal security. Express  your desire to perform well... Difficult Interview Questions Page -1       Question 1: Tell me about yourself ? Answer: Whenever
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
Java Programming: Chapter 1 Quiz Answers
Sample Quiz Answers For Chapter 1 THIS PAGE CONTAINS SAMPLE ANSWERS to the Quiz on Chapter 1 of this on-line Java textbook. Note... 1: One of the components of a computer is its CPU. What is a CPU and what
More APIs Become Available
More APIs Become Available       3. More APIs Become Available: Some APIs and new methods have been added in JDBC 6.0. More APIs have been added to this version of JDBC to provide access

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.