?
Solved

How to insert values from a Java array into fields?

Posted on 2003-03-06
3
Medium Priority
?
1,382 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
  • 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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
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

569 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