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

  • Home
  • SEARCH
  • 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 6887725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:55:11+00:00 2026-05-27T05:55:11+00:00

During the development of a software, I need to execute a statement which is

  • 0

During the development of a software, I need to execute a statement which is stored as a string. Say for example:

String test = " int a; ";

In the above example, I want to declare a variable a.

Another example is the execution of a mysql statement from a string:

String sqlquery ="SELECT * FROM FULLDETAILS WHERE Classname = 'test' ";
            con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/executable","root","mysql");
             st = (Statement) con.createStatement();
             rs = st.executeQuery(sqlquery);
                          ^

I want to achieve this for Java statements too. Is there a way?

EDIT :

The above given is an example, the real situation is much different (but the thing I basically need is the same).

The situation is that, I have a number of jpanels and I want to add some components to it, say a label, the content of the label is obtained from a database, and its only during runtime I can know, to which panel I should add the component. In this case, I cannot designate the panel by name, say if I have 10 jpanels, I thought I could use a string like:

String test = " jpanel " + i + " .add(jlabel1); " ;

will result in the value of test will be:

jpanel1.add(jlabel1); // provided i is a string with value of i is 1

now I want to execute this. Is there a way?

  • 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-05-27T05:55:12+00:00Added an answer on May 27, 2026 at 5:55 am

    Maybe that’s not what you want, but you may use Java’s Reflection API carefully to call methods or something else based on (for example) strings.

    SQL statements are far different, as they are not really executed by inside Java, they are processed by some additional SQL Server on the other side of the JDBC connection.

    Somewhere, you should have an initial list of all your panels or create it at startup or whatever if I am right?
    You should go and find a datastructure to hold them (a HashMap seems suitable, for example), add all Panels and use a key to get them back and add labels as you want.

    Rough example:

    Map<Integer, Panel> panelMap = ...
    for(int i = 1; i < 10; i++) {
        Panel panel = new Panel();
        panelMap.put(i, panel); 
    }
    
    panelMap.get(1).addLabel(labelForPanel1); (for all labels)
    

    Variable names are more or less irrelevant when the program executes, they are all objects then. Hope that suits your needs a bit more…or maybe now I missed totally 🙂

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

Sidebar

Related Questions

During software development, there may be bugs in the codebase which are known issues.
Usually, during software development, there are all sorts of utility functions I need. Like
Let's say I prefer debugging a release build of my software during development. What
During development, I usually test ASP.Net applications using the Web Development Server (sometimes called
How can I password protect my website during development with htaccess in Cakephp? which
During development, I want to create run configurations for several activities within my App,
(apologies for the somewhat lengthy intro) During development of an application which prefaults an
During development I have to test using several different hosts. It is a pain
Occasionally, during development/debugging, I want to ensure that an object is of a certain
During development I have to clear cache in Firefox all the time in order

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.