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



Home Answers Viewqa Java-Beginners More than 1 preparedStatement object

Have Programming Question? Ask it here!
 
 
 


Kriti
More than 1 preparedStatement object
1 Answer(s)      5 years and 3 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
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">
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
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
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 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
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
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
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
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
object
object  is it possible to create object in the same class..?.   Yes, you can. class CreateObject { CreateObject(){ System.out.println("I have an object."); } public static void main(String[] args
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
Insert an object with the add(Object) method
the usage of the add(Object) method in more detail. Create a class "... Insert an object with the add(Object) method       In this section you will learn to insert an object
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
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
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
JavaScript Array undefined
to print an array element more than the declared size of element that an array object hold in it. The Tutorial depicts an example from JavaScript Array Undefined... the array length  is more than the declared variable, then document. write
function 1 - Java Beginners
function 1  WAP to calculate the value of x,where x=tan(A)+tan(B)/1+tan(A)*tab(B)  Give more details like how to calculate and what is tan(A) and tan(B),etc
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   
Which method is more efficient?
Which method is more efficient?  I'm faced with initializing a bunch of text fields in java. The problem is that the number of text fields is quite... them. I want to know if this is better than using several lines to initialize
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
object of object class
object of object class  what do u mean by "object of object class
more circles - Java Beginners
more circles  Write an application that uses Circle class you created... createCircle() that o reads a radius of a circle from the user o creates a circle object, and o returns the object. ? The program creates a circle object by using
AgileJ StructureViews
;  AgileJ StructureViews code visualizer for Eclipse is: 1 Specialized for Reverse Engineered Diagrams - more akin to an extension to the Eclipse Java browsing perspective than a drawing tool. 2 Dedicated to Java
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
PHP Date add 1 hour
In the following example code we are showing how you can add one hour to a date object. <?php //This PHP Example code shows how to add one hour to a date object $todayDate = date("Y-m-d g:i a");// current
Replace an object with set(int, Object) method
that provides the usage of the set(int, object) method in more detail.  Create... Replace an object with set(int, Object) method       In this section you will learn to replace an object
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
data insertion and fetch 1
data insertion and fetch 1  @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html>...+"','"+Choice+"')"; PreparedStatement ps=(PreparedStatement) con.prepareStatement
 

 

 

DMCA.com