+++++++++++++++++++++++二个字,好闷~~~~++++++++++++++++++++++++++++++++++++++++++ PreparedStatement stmt=conn.preparetatement(sql);修改成PreparedStatement stmt=conn.prepareStatement(sql); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class CheckSQLValue { /** * 传入SQL变量的类型 */ /* 日期型 */ public static final int INT_SQLTYPE_DATE = 1; /* 数值型 */ public static final int INT_SQLTYPE_NUMBER = 2; /* 字符型 */ public static final int INT_SQLTYPE_STRING = 3; /** * SQL 敏感字符 */ public static final String[] STR_SQL_CMD = new String[] { "CREATE", "DROP", "ALTER", "INSERT", "DELETE", "UPDATE", "SELECT", "sp_", "EXEC", "OR", "AND" }; /** * 检验输入SQL的变量内容 用于限定长度的字符串类型 */ public static String checkValueForSQL(String string, int inType, int inMaxLength) throws Exception { /* 字符串型 */ if (inType == CheckSQLValue.INT_SQLTYPE_STRING) { /* 超长则截断字符串 */ if (string.length() > inMaxLength) { string = string.substring(0, inMaxLength); } /* 进入下一个函数再次过滤 */ string = checkValueForSQL(string, inType); } return string; } /** * 检验输入SQL的变量内容 */ public static String checkValueForSQL(String string, int inType) throws Exception { /* 日期型数值 */ if (inType == CheckSQLValue.INT_SQLTYPE_DATE) { /* 检测是否有无效字符 */ char chTMP = ' '; for (int i = 0; i < string.length(); i++) { chTMP = string.charAt(i); if ((chTMP < '0' || chTMP > '9') && chTMP != '-' && chTMP != ' ' && chTMP != ':') { /* 存在无效字符 将STRING置空 */ string = ""; break; } } } /* 数值型 */ if (inType == CheckSQLValue.INT_SQLTYPE_NUMBER) { /* 检测是否有无效字符 */ char chTMP = ' '; for (int i = 0; i < string.length(); i++) { chTMP = string.charAt(i); if ((chTMP < '0' || chTMP > '9') && chTMP != '-' && chTMP != '+' && chTMP != '.') { /* 存在无效字符 将STRING置空 */ string = ""; break; } } } /* 字符串型 */ if (inType == CheckSQLValue.INT_SQLTYPE_STRING) { /* 转换单引号 */ string = string.replaceAll("'", "''"); /* 转换敏感字符 */ String strUP = string.toUpperCase(); for (int i = 0; i < STR_SQL_CMD.length; i++) { if (strUP.indexOf(STR_SQL_CMD[i]) != -1) { int inIndex = strUP.indexOf(STR_SQL_CMD[i]); string = string.substring(0, inIndex) + "'+'" + string.substring(inIndex, inIndex + STR_SQL_CMD[i].length()) + "'+'" + string.substring(inIndex + STR_SQL_CMD[i].length(), string.length()); } } } return string; }} 楼主,建议你看看jsp的基础,这些东西都有的,或者在提问前搜索一下有没有类似的帖子,这样子问效率不高,还浪费分。我只是建议,我也算是新手! PreparedStatement stmt=conn.preparetatement(sql);少了个s啊,怎么可能对呢Statement String sql="select * from corp_members where user_name=?";//PreparedStatement stmt=conn.prepareStatement(sql);//stmt.setString(1,user_name);//rs=stmt.executeQuery();//这样不行 PreparedStatement stmt=conn.prepareStatement(sql); Connection的对象conn的预查询conn.executeQuery(sql); 普通查询conn.prepareStatement(sql);细节可参考API,在IDE中也是有预显示功能可看到其方法的 建议楼主用Eclipse,JB这样的工具,可以避免犯类似的错误。 你没用IDE吧,用WSAD或者JB看看 那我下载个下来了吧.我是用dreamweaver的啊. xx.conn 你这个类的内容是什么啊 按照你上面出现的错误 这个类返回的好象是Statement类型 把这个类的源码贴出来 dreamweaver开发个人网站,做漂亮的网页还行。但是他不是和用来开发企业级的应用程序的,企业级的应用这方面,dreamweaver太弱了。 Eclipse有中文,而且开源挺好用 现在仅求解决方法.不论什么方法.(防SQL注入式漏洞) 现在仅求解决方法.不论什么方法.(防SQL注入式漏洞) 关于jsp标签求救 散分啦,关于监听器的配置 网站和论坛的用户登陆不能同步 如何把字符串转化为double 或是float 形 急!lucene内存溢出问题,怎样解决? 急:有没有河南的朋友,熟悉APPLET、JMF,有音视频聊天室开发经验者 我很疑惑,为什么要学hibernate,网上有一些资料,但我看了之后,人不明其理,请大家讨论一下,hibernate到底能带来什么,应该怎么学呢 html:select中如何使用CSS? 解决问题立即给分,从没有食言过! 如此上传文件为何出错? 请问大哥们!smartupload组件在哪里有下载啊 谁有用java写的存储过程的例子,给我传一个
public class CheckSQLValue { /**
* 传入SQL变量的类型
*/ /* 日期型 */
public static final int INT_SQLTYPE_DATE = 1; /* 数值型 */
public static final int INT_SQLTYPE_NUMBER = 2; /* 字符型 */
public static final int INT_SQLTYPE_STRING = 3; /**
* SQL 敏感字符
*/
public static final String[] STR_SQL_CMD = new String[] { "CREATE", "DROP", "ALTER", "INSERT", "DELETE", "UPDATE", "SELECT", "sp_", "EXEC", "OR", "AND" }; /**
* 检验输入SQL的变量内容 用于限定长度的字符串类型
*/
public static String checkValueForSQL(String string, int inType, int inMaxLength) throws Exception { /* 字符串型 */
if (inType == CheckSQLValue.INT_SQLTYPE_STRING) { /* 超长则截断字符串 */
if (string.length() > inMaxLength) {
string = string.substring(0, inMaxLength);
} /* 进入下一个函数再次过滤 */
string = checkValueForSQL(string, inType); } return string;
} /**
* 检验输入SQL的变量内容
*/
public static String checkValueForSQL(String string, int inType) throws Exception {
/* 日期型数值 */
if (inType == CheckSQLValue.INT_SQLTYPE_DATE) { /* 检测是否有无效字符 */
char chTMP = ' ';
for (int i = 0; i < string.length(); i++) {
chTMP = string.charAt(i);
if ((chTMP < '0' || chTMP > '9') && chTMP != '-' && chTMP != ' ' && chTMP != ':') { /* 存在无效字符 将STRING置空 */
string = "";
break;
}
}
} /* 数值型 */
if (inType == CheckSQLValue.INT_SQLTYPE_NUMBER) { /* 检测是否有无效字符 */
char chTMP = ' ';
for (int i = 0; i < string.length(); i++) {
chTMP = string.charAt(i);
if ((chTMP < '0' || chTMP > '9') && chTMP != '-' && chTMP != '+' && chTMP != '.') { /* 存在无效字符 将STRING置空 */
string = "";
break;
}
}
} /* 字符串型 */
if (inType == CheckSQLValue.INT_SQLTYPE_STRING) { /* 转换单引号 */
string = string.replaceAll("'", "''"); /* 转换敏感字符 */
String strUP = string.toUpperCase();
for (int i = 0; i < STR_SQL_CMD.length; i++) {
if (strUP.indexOf(STR_SQL_CMD[i]) != -1) {
int inIndex = strUP.indexOf(STR_SQL_CMD[i]);
string = string.substring(0, inIndex) + "'+'" + string.substring(inIndex, inIndex + STR_SQL_CMD[i].length()) + "'+'" + string.substring(inIndex + STR_SQL_CMD[i].length(), string.length());
}
}
} return string;
}
}
少了个s啊,怎么可能对呢
Statement
//PreparedStatement stmt=conn.prepareStatement(sql);
//stmt.setString(1,user_name);
//rs=stmt.executeQuery();//这样不行
普通查询conn.prepareStatement(sql);细节可参考API,在IDE中也是有预显示功能可看到其方法的
挺好用