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;