请帮助..
如何在JDO INSERTION时阻止SQL注入?
我的JDO类是MyData.Java
package com.jdo;
import java.util.Date;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.IdentityType;
@PersistenceCapable(identityType = IdentityType.APPLICATION,detachable="true")
public class MyData{
@PrimaryKey
@Persistent
private String id;
@Persistent
private String name;
@Persistent
private String address;
@Persistent
private Date addedDate;
/**
*
* @param id
* @param name
* @param address
*/
public MyData(String id,String name,String address) {
super();
this.id=id;
this.name=name;
this.address=address;
this.addedDate = new Date();
}
/**
* @return id
*/
public String getId(){
return this.id;
}
/**
*
* @return name;
*/
public String getname(){
return this.name;
}
/**
*
* @return addedDate
*/
public Date getAddedDate(){
return this.addedDate;
}
/**
*
* @param id
*/
public void setId(String id){
this.id=id;
}
/**
*
* @param name
*/
public void setName(String name){
this.name=name;
}
/**
*
* @param addedDate
*/
public void setaddedDate(Date addedDate){
this.addedDate=addedDate;
}
}
我试图使用
插入MyData user=new MyData ("id001","Shana","Address");
user=MyDataDAO.saveData(user);
它成功保存在表中。但我需要阻止它从SQL注入...请帮助?
答案 0 :(得分:1)
通过将纯文本字符串与SQL字符串连接来创建查询时,会发生SQL注入。
如果
,您无需担心上面的代码看起来属于第2类。