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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:46:20+00:00 2026-06-15T16:46:20+00:00

I am trying to validate data before inserting them into the database(POSTGRESQL). The data

  • 0

I am trying to validate data before inserting them into the database(POSTGRESQL). The data corresponding to email, zip code etc are easily validated with the use of Apache Commons Validator. But in case of names I used this:

^[a-zA-Z][ a-zA-Z]{1-30}$

This prevents any special characters from being added as name, but it fails to prevent users from adding DROP or GRANT as a name. As I am using PreparedStatement, I didn’t think it was going to be a problem but it is now required that SQL keywords shouldn’t go in the db as it may lead to a Second Order SQL Injection.

I thought of using blacklisting all SQL keywords (surely, this will prevent Huge Grant from logging into our site. :P) but it seems that there are >64 keywords. Is this (Blacklist filtering data for SQL Keywords) a proper approach for preventing Second Order SQL Injection? What are my options?

I am using this code:

String sql="INSERT INTO users (username, password, name) VALUES (?,?,?);";
        try{
            conn=SomeStaticClass.createConnection();
            ps=conn.prepareStatement(sql);
            ps.setString(1, dataBean.getUsername());
            ps.setString(2, dataBean.getPassword());
            ps.setString(3, dataBean.getName());
            ps.execute();
        }catch(SQLException e){
            e.printStackTrace()
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            try{
                if(ps!=null){
                    ps.close();
                }
                conn.close();
            }catch(SQLException e){
                e.printStackTrace();
            }
        }
  • 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-15T16:46:21+00:00Added an answer on June 15, 2026 at 4:46 pm

    Second order injection only occurs if you store the keywords in the database and then later use them in an unsafe manner. If you use prepared statements and they are properly parameterized it won’t occur. Cisco have a good summary of understanding SQL injection:

    http://www.cisco.com/web/about/security/intelligence/sql_injection.html

    Apart from your example of “Grant” there are also many such as IF, BY, IS, IN, TO that will occur very commonly in English language / names.

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

Sidebar

Related Questions

I'm trying to validate some form data before adding it to a database however
I am trying to get JavaScript to validate all data in a form before
I'm trying to validate data passing between client/server for a location-based application and I
While trying to validate form data on my page i get the following error:
I'm trying to validate a class decorated with data annotation with the Validator class
I am trying to validate two checkboxes. One of them must be checked in
I'm been trying to validate Data in a Flex TextFiled, and I've encountered some
I'm trying to validate a pair of data columns on mysql from my php
I am trying to validate a form and save it in my database. I
i am trying to validate a form before adding the visitor info to a

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.