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.
kpoojaAsked:
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.

heyhey_Commented:
your question is too general - read the JDBC tutorial first (www.javasoft.com).
0
setiawanCommented:
Hi kpooja, I assumed that you have already know how to connect to database server using Java ODBC-JDBC

if you have problem, see :
http://codeguru.developer.com/java/articles/485.shtml

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);
 theConn.dbConn.commit();
 stmt.close();



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();
   theConn.dbConn.commit();
   stmt.close();
   System.out.println(sql);            
   }
 catch (Exception e){
   e,printStackTrace();
   }

taken from : http://codeguru.developer.com/java/articles/487.shtml
0
Ravindra76Commented:
Hi kpooja,

I did n't completely understand your goal.

It is static.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

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


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

pst = con.prepareStatement(query);
pst.setString(1,s);
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


0
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).

Ravindra76Commented:
Hi kpooja,

 I did n't see setiawan  comments before answering.

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

All the Best
0

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
heyhey_Commented:
Proposed Answer
From: rkruba
Date: Friday, December 03 1999 - 01:43AM PST
The above comments themselves answers your question..

....
0
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
Java

From novice to tech pro — start learning today.