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 8934743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:51:21+00:00 2026-06-15T09:51:21+00:00

I need to read in the ‘public static NEW_QUERY’ from another class, but it

  • 0

I need to read in the ‘public static NEW_QUERY’ from another class, but it has variables inside of the query that is changed when the method is called. How can I call this ‘public static’ and get the updated QUERY from another class.

Here is the Java Code;

package artemispm.autocalc;

import java.sql.*;
import java.util.*;
import a7.unittests.dao.UnitTestHelper;
import artemispm.serverutil.*;
import artemispm.trdo.*;
import artemispm.parser.*;

public abstract class TRBaseScoreCalculator implements ExpressionParserLookup {
                           
/******THIS IS THE PLACE I NEED TO HAVE CORRECTED**********/
/*HOW DO I FORCE THIS TO PUSH VALUES INTO 'match' and 'useFor'*/
/**SO THAT I CAN CALL NEW_QUERY FROM ANOTHER CLASS *****/
/****IT SAYS 'match' and 'useFor' cannot be resolved****/

public static String NEW_QUERY = "select count(userfieldid) from tr_userfield where calcexpression like '%" + match + "%'and usefor like '%" + useFor +"%'";

public Connection               m_con;
protected String                m_characName        = "";

public boolean isThisCharacInUse(Connection con, String characName,String useFor) 
throws SQLException, TRException {
    boolean result;        
    String match = "[" + TRBaseSql.rewrapQuotes(characName) + "]";
  
    if(TRBaseSql.getDatabaseType(con) == TRBaseSql.DBTYPESQLSERVER) {
        match = "[[]" + TRBaseSql.rewrapQuotes(characName) + "]";
    }
    
    TRSystemSQL sql = new TRSystemSQL();
    TRSystem sys=sql.getSystem(con);
    result =    (   sys.getScoreCalculation() != null 
                &&  sys.getScoreCalculation().indexOf(match) >= 0  );
    if (result) return(result);
    else {
        
        int count;

        /*****THIS IS THE PLACE I NEED HELP AT  12/5/2012 ******/

        count = sql.executeGetInt(con, NEW_QUERY , null);
        
        if (count > 0) return true;
        count = sql.executeGetInt(con, 
                "select count(characid) from tr_charac where calcexpression like '%" + match + "%'and usefor like '%" + useFor +"%'" , null);
        return (count > 0);
        }
}
}

In addition to this, which I have not attempted here, but I am supposed to as it is in the specs:

  • Locate all embedded sql statements and implement constants for embedded sql which does not already use constants.

  • Replace any string concatenation within Sql statement creation with String.format().

  • For any String.format commands you must escape out any existing % symbols. These symbols are often used in LIKE operations.

    What I am doing is Unit Testing each Query, from another file, to make sure they are correct for data migration from a MSSQL Server 2005 to MYSQL

IS THE BELOW THE BEST SOLUTION GIVEN THE STRING.FORMAT SPEC. IS THIS CORRECT. THE TEST DOES PASS, BUT I THOUGHT I WAS SUPPOSED TO CHANGE AS LITTLE OF THE ORIGINAL CODE AS POSSIBLE

package artemispm.autocalc;

import java.sql.*;
import java.util.*;
import a7.unittests.dao.UnitTestHelper;
import artemispm.serverutil.*;
import artemispm.trdo.*;
import artemispm.parser.*;

public abstract class TRBaseScoreCalculator implements ExpressionParserLookup {
                           
/******THIS IS THE PLACE I NEED TO HAVE CORRECTED**********/
/*HOW DO I FORCE THIS TO PUSH VALUES INTO 'match' and 'useFor'*/
/**SO THAT I CAN CALL NEW_QUERY FROM ANOTHER CLASS *****/
/****IT SAYS 'match' and 'useFor' cannot be resolved****/

public static String NEW_QUERY = String.format( "select count(userfieldid) from tr_userfield where calcexpression like %s and usefor like %s", "?", "?");

public Connection               m_con;
protected String                m_characName        = "";

public boolean isThisCharacInUse(Connection con, String characName,String useFor) 
throws SQLException, TRException {
    boolean result;        
    String match = "[" + TRBaseSql.rewrapQuotes(characName) + "]";
  
    if(TRBaseSql.getDatabaseType(con) == TRBaseSql.DBTYPESQLSERVER) {
        match = "[[]" + TRBaseSql.rewrapQuotes(characName) + "]";
    }
    
    TRSystemSQL sql = new TRSystemSQL();
    TRSystem sys=sql.getSystem(con);
    result =    (   sys.getScoreCalculation() != null 
                &&  sys.getScoreCalculation().indexOf(match) >= 0  );
    if (result) return(result);
    else {
        
        int count;

        /*****THIS IS THE PLACE I NEED HELP AT  12/5/2012 ******/

        PreparedStatement stmt = con.prepareStatement(TRBaseScoreCalculator.NEW_QUERY);
        stmt.setString(1, "%"+match+"%");
        stmt.setString(2, "%"+useFor+"%");
        
        count = sql.executeGetInt(con, stmt.toString() , null);
        
        if (count > 0) return true;
        count = sql.executeGetInt(con, 
                "select count(characid) from tr_charac where calcexpression like '%" + match + "%'and usefor like '%" + useFor +"%'" , null);
        return (count > 0);
        }
}
}
  • 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-15T09:51:22+00:00Added an answer on June 15, 2026 at 9:51 am

    Static variables/methods are associated with lass definition and hence you can’t use any non-static variable/method in them.

    if your match and useFor are not static(that is the case) then you can’t have a static qquery like this:

    public static String NEW_QUERY = “select count(userfieldid) from tr_userfield where calcexpression like ‘%” + match + “%’and usefor like ‘%” + useFor +”%'”;

    Better to use a place holders in the query as:

     public static String NEW_QUERY = 
               "select count(userfieldid) from tr_userfield "+
                " where calcexpression like ? and usefor like ?";
    

    and the place of use, pass the value using query Parameter set methods:

       PreparedStatement stmt= con.prepareStatement(TRBaseScoreCalculator.NEW_QUERY);
       stmt.setString(1,"%"+match+"%");
       stmt.setString(1,"%"+useFor+"%");
    

    EDIT: If you want to use String.format then try below:

     public static String NEW_QUERY =  "select count(userfieldid) from tr_userfield "+
                               "  where calcexpression like '%s' and usefor like '%s'";
    

    and down the line where you are using the query string, do:

     String updatedQuery = String.format(TRBaseScoreCalculator.NEW_QUERY, 
                                          "%"+match+"%", "%"+useFor+"%");
     count = sql.executeGetInt(con, updatedQuery, null);
    

    But Still I prefer the PraparedStatement route and in that case you don’t need to unnecessary String.format.

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

Sidebar

Related Questions

I need to read 16 bits from the binary file as std::string or char
I need to read certain statistics from iw_statistics structure, here's the code: struct net_device
I need to read data from XML to a List<>. The XML file contains
I need to read the editurl from one jqgrid for use in a DND
I need to read the size of a file but the server is forcing
I need to read in an expression from a file using a string stream
I need to read and serialize objects from and to XML, Apple's .plist format
I need read in and parse data from a third party website which sends
I have a flat CSV file which I need read from to end up
I need to read the image from the specific path. I pass only path

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.