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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:29:12+00:00 2026-05-13T16:29:12+00:00

I have the below code that splits the sql statement and give its indices

  • 0

I have the below code that splits the sql statement and give its indices for the columns.

String sql = "INSERT INTO Table1(SSN, EMPID) VALUES (?,?)";

    public static List<Object[]> indices(String stmt) {
        List<Object[]> list = new ArrayList<Object[]>();
        String variables[] = null;
        try {
            variables = stmt.substring(stmt.indexOf('(')+1, 
                stmt.indexOf(')', stmt.indexOf('(')+1)).split("\\,");
        } catch (Exception e) {}

        for (int i=0; i < variables.length; ++i ) {
            Object [] str =  new Object [2] ;
            str[0] = variables[i].trim() ;
            str[1] = ((Integer)(i+1)) ;
            list.add(str) ;
        }
        return list;
    }

Result - 

list[0] >>

array[0] = SSN
array[1] = 1

list [1] >>
array[0] = EMPID
array[1] = 2

Can some one point me with appropriate regular expression to split the following sql instead –

sql = "if not exists (select * from Table1 where SSN = ? and EMPID =?)  
      INSERT INTO Table1(SSN, EMPID) VALUES (?,?)"

I guess the output would be something like –

list[0] >>
array[0] = SSN
array[1] = 1

list [1] >>
array[0] = EMPID
array[1] = 2

list[2] >>
array[0] = SSN
array[1] = 1

list [3] >>
array[0] = EMPID
array[1] = 2

Thank You

  • 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-13T16:29:12+00:00Added an answer on May 13, 2026 at 4:29 pm

    Attempting to parse non-trivial languages like SQL using regexes or other low-level string bashing is a BAD IDEA. You end up with unreadable code and a fragile “parser” that breaks when supplied with input that is invalid or valid-but-different.

    You either need to implement a proper SQL parser (or use an existing one), or change your code so that you are not parsing SQL but assembling it from something else.

    I have an application depending on a framework and don’t want to introduce new libraries!

    That is a bad reason for not doing proper parsing. What is wrong with not using another library???

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

Sidebar

Ask A Question

Stats

  • Questions 284k
  • Answers 284k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer >>> t1 = ("A", "B", "C") >>> t2 = ("1",… May 13, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer If you want to send updates to Twitter using their… May 13, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer Found it! I have to subtract the 16 bytes salt… May 13, 2026 at 4:31 pm

Related Questions

Greetings. I have written a little python script that calls MySQL in a subprocess.
Current, I've got a stored procedure that has a main goal of doing a
The Question Aside from all the obvious answers, what would cause extension methods to
I have to convert some code from classic ASP to ASP.NET 1) How can
I have two DataGridView controls, with three buttons in between them vertically, in a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.