Insert Statement in Java Sql Programming

I am new in Java ODBC-JDBC programming. hence i am facing lot of problems with the database designing and updating.
pls guide me for the following :
 How to write the Dynamic Insert statement and its processing with the existing database. If possible, explain with the code.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

your question is too general - read the JDBC tutorial first (
Hi kpooja, I assumed that you have already know how to connect to database server using Java ODBC-JDBC

if you have problem, see :

Statement stmt;
 String sql;    
 int rows;      

 sql = "INSERT INTO tCust " 
     + "(custId, custName, custAddr) "
     + "VALUES "
     + "('" + custId   + "',"
     + "('" + custName + "',"
     + "('" + custAddr + "')";

 stmt = theConn.dbConn.createStatement();
 rows = stmt.executeUpdate(sql);

A PreparedStatement is used to insert data containing QUOTES

 PreparedStatement stmt = null;
 String sql;    
 int rows;      

 try {
   sql = "INSERT INTO tCust"
         + "(custName) "
         + "VALUES "
         + "(?)";
   stmt = theConn.dbConn.prepareStatement(sql);
   stmt.setString(1, "Name with \" are permitted!");
   rows = stmt.executeUpdate();
 catch (Exception e){

taken from :
Hi kpooja,

I did n't completely understand your goal.

It is static.


 con = DriverManager.getConnection("jdbc:odbc:yourdsn");

query = "insert into yourtable(yourname) values (?)";

pst = con.prepareStatement(query);
int i = pst.executeUpdate();

Dynamic: -

I don't know you requirement.

In dynamic, the query string may contain dynamic ? and correspondingly set statemtns for preparedStatement for thers ?.

Can you tell what exactly you require

Best of luck

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Hi kpooja,

 I did n't see setiawan  comments before answering.

I think it is clear to you know
The above comments themselves answers your question..
Please be specific with your question?
So that you can get answers..

All the Best

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Proposed Answer
From: rkruba
Date: Friday, December 03 1999 - 01:43AM PST
The above comments themselves answers your question..

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.