A SQL injection attack consists of insertion or "injection" of a SQL query via the input data from the client to the application.
A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file present on the DBMS file system and in some cases issue commands to the operating system. SQL injection attacks are a type of injection attack, in which SQL commands are injected into data-plane input in order to effect the execution of predefined SQL commands.
You need to make sure that you never string-concatenate user-controlled input straight in the SQL query and that you are using parameterized queries all the way. Any ORM library (Hibernate...) have already taken this into account. If you are working with raw JDBC, you need to ensure that you set user-controlled input using PreparedStatement instead of Statement.
Example:
String selectSQL = "SELECT USER_ID, USERNAME FROM DBUSER WHERE
USER_ID = ?";
PreparedStatement preparedStatement =
dbConnection.prepareStatement(selectSQL);
preparedStatement.setInt(1, 1001);
ResultSet rs =
preparedStatement.executeQuery(selectSQL);
while (rs.next())
{
String userid = rs.getString("USER_ID");
String username = rs.getString("USERNAME");
}