?
Solved

How to insert values from a Java array into fields?

Posted on 2003-03-06
3
Medium Priority
?
1,381 Views
Last Modified: 2008-03-06
Hi everyone, could anyone please help me solve my problem.
I have an array of Strings size 18. How do i insert values from my array to the table>
0
Comment
Question by:zloy_ochen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 80 total points
ID: 8082736
for example:

String[] yourStrings = new String[18];
yourStrings[0] = "Hello";
yourStrings[1] = "World";
yourStrings[2] = "foo";
... etc

// open a connection to your database
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/<yourdatabase>?user=<user>&password=<password>");

Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM table1");
rs.moveToInsertRow();
for (int i=0;i<yourStrings.length;i++) {
   rs.updateString(yourStrings[i]);
}
rs.insertRow();
rs.close();
stmt.close();
conn.close();
0
 
LVL 1

Author Comment

by:zloy_ochen
ID: 8088301
Thank u , for yr effort, but thtats not the answer i am looking for. I need to create a new field not to update already existing field.
0
 
LVL 1

Author Comment

by:zloy_ochen
ID: 8089888
Sorry for missunderstading the answer.Thank you  bobbit31
0

Featured Post

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question