Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8157967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:28:12+00:00 2026-06-06T17:28:12+00:00

I have different values in different classes. I need to insert them in the

  • 0

I have different values in different classes. I need to insert them in the same table. For example, by trying the example in this tutorial here: http://www.vogella.com/articles/MySQLJava/article.html

If I have such code (assuming the DB connection successfully done in another class):

// PreparedStatements can use variables and are more efficient
    preparedStatement = connect.prepareStatement("insert into  FEEDBACK.COMMENTS
                         values (default, ?, ?, ?, ? , ?, ?)");
            // "myuser, webpage, datum, summery, COMMENTS from FEEDBACK.COMMENTS");
            // Parameters start with 1
            preparedStatement.setString(1, "Test");
            preparedStatement.setString(2, "TestEmail");
            preparedStatement.setString(3, "TestWebpage");
            preparedStatement.setDate(4, new java.sql.Date(2009, 12, 11));
            preparedStatement.setString(5, "TestSummary");
            preparedStatement.setString(6, "TestComment");
            preparedStatement.executeUpdate();

Assume that in one class I want to insert value 1, in the second class, I want to insert value 2, etc. By the end of my program, in the main function, I want to execute the update. Note that I wrote the:

preparedStatement = connect.prepareStatement("insert into  FEEDBACK.COMMENTS 
                    values (default, ?, ?, ?, ? , ?, ?)");

is in the main function. I have tried to define preparedStatement as public variable in the class that contains the main function, and if, for example, I need to insert value 2 in another class, I type:

preparedStatement.setString(2, "TestEmail");

but this results in error in the main function says: No value specified for parameter 2. So, how can I insert values from different classes in one table ??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T17:28:13+00:00Added an answer on June 6, 2026 at 5:28 pm

    Since you are using “preparedStatement” variable in main, I assume it must be a public static variable. And since you expect other classes to execute methods on this variable, I am assuming you are doing it in static initializers of these classes or in static constructors. The problem is these classes are not loaded (and hence their static initializers are not run) unless you reference these classes from main (calling a static method on the class or creating a new instance). I think you are not doing so. That is why none of the static initializers of these classes are run and you don’t have an preparedStatement that is ready to be executed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with different values for different countries, for example: id| country
I have table nol_voa with different values and I am importing xml file with
I have two classes that extend the same abstract class. They both need the
I have a some classes which I need to serialize in two different ways:
Various online services have different values for maximum year of expiry, when it comes
I have one key but different values for that key. I tried HashTable but
I have an object with different values that is name,nameid, lifebeging,lifeEndiging .... etc, for
I have ArrayProxy filled with different values, and after tossing it in iterator and
i have a function to calculate several different values: int ASPfile::get_dimensions(int* Lat, int* Lon,
Suppose I have 3 radio buttons with different values for each radio button and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.