473,499 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Which one of jdbc parameter passing is safer from SQL injection

1 New Member
Below I am using two different ways to pass parameters to SQL queries.

1st Method

Expand|Select|Wrap|Line Numbers
  1. String sql = "insert into db_table (associateid,comment) values(:associateId,:comments)";
  2.     Map<String, Object> paramMap = new HashMap<String, Object>();
  3.     paramMap.put("associateId", "12345");
  4.     paramMap.put("comments", "some comments");
  5.     int rowNumber = readTemplate.update(sql, paramMap);

2nd Method

Expand|Select|Wrap|Line Numbers
  1.  String sql = "insert into db_table (associateid,comment) values(:associateId,:comments)";
  2.     int rowNumber = readTemplate.update(sql, new MapSqlParameterSource().addValue("associateId", "12345").addValue("comments", "some comments"));

Which one is safer from SQL injection ? If possible please give a reason why it is safe ?

Thanks in Advance
Aug 5 '16 #1
1 2402
Kara Hewett
27 New Member
The initial code example is not vulnerable to SQL injection because it correctly uses parameterized queries. By using java's PreparedStatement class, bind variables and corresponding string methods, SQL injection can be easily prevented. The second example uses dynamic queries to concatenate potentially malicious data. The second example doesn't bind parameters and values therefore injection can occur within the string.
Aug 29 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1386
by: Mat Andrews | last post by:
Hi, I'm comfused with this peice of code which I'm looking at. I can't figure out how it works (and it does appear too); ApplicationData appData = new ApplicationData(); ...
0
1518
by: KK | last post by:
Hi MCPP gurus' I have a small problem in parameter passing.This is my situation namespace Abc { public __gc class ClassAbc { public: String* Hello(String* str) {
0
1661
by: stevag | last post by:
I have stored a variable ABC in a ASP.NET page and I use xsltArglist.AddParam in order to add this variable as a parameter to the binded XSLT transformation. In the associated .xslt file I use...
0
1532
by: Richard Buckshaw | last post by:
Mimick the older C/ pascal dll parameter passing convention? - VB Class Mod? Hello, I have been attempting to write a VB class that would expose its stuff to an older (ok, legacy application)...
2
4278
by: Geoff | last post by:
Consider the procedure Private Sub Adder(ByVal Num1 As Integer, etc. ) End Sub
3
4958
by: kavallin | last post by:
I wonder if anyone has compared the db2 universal jdbc driver type 2 and 4 with the legacy db2 driver. Which one is the best to use ? I'm working in a project where the envm looks like this ...
1
2444
by: vijay.gandhi | last post by:
Hello, I have created a function in C++/CLI which was exported as a .DLL to be used in VB .NET. I have been having some problems (I think it has to do with the right syntax) with parameter...
16
3353
by: Theo R. | last post by:
Hi all, Does the C99 Standard explicitly mention the need for a stack for passing arguments or Is this platform specific? As an example, the ARM9 processor recommends Core Registers R0-R3 be...
13
1673
by: frakie | last post by:
Hi 'body, I'm experiencing difficulties on parameter passing. I wrote a library in last months, and now it crashes few times in a month because of errors in parameter passing: using gdb on the...
1
2235
by: tarunkhatri | last post by:
Hi, I want to pass the parameter of employee_id to a page. My code is working fine and passing parameter to page but the problem is rather then the current parameter. It passed the parameter which...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.