sql解析java
import java.sql.Connection。
2. JavaSql闂棰
if (id.equals(rs.getString(1))&& password.equals(rs.getString(2)))
鍒嗗紑,锅氭垚浜屾℃浔浠惰鍙
闂棰樻槸sql镄勬敞鍏ユ纺娲
鍒嗗埆鐢盢ameTxt锛孭wdTxt鎺ュ弹椤甸溃杈揿叆鐢ㄦ埛钖嶅拰瀵嗙爜锛岀劧钖庢瀯阃犲备笅sql璇鍙ワ细
select * from [User] where userName = '" + NameTxt + "钬檃nd userPassword = '" + PwdTxt + "'";
姣斿备綘镄勭敤鎴峰悕涓簓our锛屾垜涓岖煡阆揿瘑镰侊纴浣嗘槸鎴戝湪"鐢ㄦ埛钖"澶勮緭鍏 your '--"
select * from [User] where userName='your '-- 'and userPassword =....
娉ㄦ剰"--",浼氭妸钖庤竟镄剆ql浣滀负娉ㄩ喷锛岃繖灏辨槸sql娉ㄥ叆銆
03-05骞存瘆杈冩祦琛宻ql娉ㄥ叆锛屼篃鍙阃氲繃鍦板潃娉ㄥ叆(浣跨敤QueryString浼犲弬鏁)锛屽傛灉𨱒冮檺瓒冲燂纴浣曚互镓ц寀pdate/delete璇鍙
3. java 怎么用正则表达式解析sql中的表名,已有半成品,求改善
Stringstr="from\s+(.*)\s+where?";
Stringsql="select*fromtable,table2wherea=b";
Patternp=Pattern.compile(str);
Matchermatcher=p.matcher(sql);
while(matcher.find()){
Stringstring=matcher.group(1);
System.out.println(string);
}
4. 杩欐礿ava褰扑腑镄剆ql浠涔堟剰镐濓纻
public List getShopList(String keyword) {//鏂规硶 浠庡栭儴鎺ユ敹涓涓鍙傛暟keyword
List<Shop> ret = new ArrayList<Shop>();
super.openConn();
String sql = "select * from dianmian ";
if (null!=keyword && !"".equals(keyword.trim())){//濡傛灉keyword涓岖瓑浜峦ull鎴栬卥eyword涓崭负""keyword.trim()铡绘帀绌烘牸
sql += "where name like '%"+keyword+"%'";
sql += "or desc like '%" + keyword + "%' ";
sql += "or goods like '%" + keyword + "%' ";
sql += "or postion like '%" + keyword + "%' ";
sql += "or links like '%" + keyword + "%' ";
}
System.out.println("SQL: " + sql);
sql+=鍗
sql=sql+"";
鏋勯爏ql璇鍙
5. java解析字符串(解析sql语句,得到需要查询显示的字段名)。
在Sql语句前加上SET FMTONLY ON,再执行Sql语句,该设置只将元数据返回给客户端,可以用于测试响应的格式,而不必实际执行查询.有了返回的表结构,还怕得到不到要查询的字段
例:
SET FMTONLY ON;
SELECT f_spbm,f_spmc as '名称' FROM 表1;
SET FMTONLY OFF;