政策查询java
package wangzhan; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; public class Thesql { public Connection connect; public Thesql() throws Exception { Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://localhost:3306/zhengce"; String username = "root"; String password = "qq2665410029"; connect = DriverManager.getConnection(url, username, password); } public void finalize() throws Exception { connect.close(); } public Pd_zhengce policy_query(String id) throws Exception { String sql="select * from policy where id = ?"; PreparedStatement pre = connect.prepareStatement(sql); pre.setString(1,id); ResultSet rs = pre.executeQuery(); Pd_zhengce pdd = new Pd_zhengce(); while(rs.next()) { pdd.id=rs.getInt(1); pdd.name=rs.getString(2); pdd.type=rs.getString(3); pdd.category=rs.getString(4); pdd.range=rs.getString(5); pdd.document=rs.getString(6); pdd.form=rs.getString(7); pdd.organ=rs.getString(8); pdd.viadata=rs.getString(9); pdd.pubdata=rs.getString(10); pdd.perdata=rs.getString(11); pdd.field=rs.getString(12); pdd.theme=rs.getString(13); pdd.keyword=rs.getString(14); pdd.superior=rs.getString(15); pdd.precursor=rs.getString(16); pdd.succeed=rs.getString(17); pdd.state=rs.getString(18); pdd.text=rs.getString(19); pdd.pdf=rs.getString(20); pdd.redundancy=rs.getString(21); pdd.rank=rs.getString(22); pdd.policyk=rs.getString(23); pdd.newrank=rs.getString(24); pdd.year=rs.getString(25); pdd.newkey=rs.getString(26); pdd.secondtheme=rs.getString(27); pdd.allsum=rs.getInt(28); } pre.close(); if(pdd.id!=0) return pdd; else return null; } public Pd_zhengce[] policy_DimQuery(String mingcheng,String zihao,String jigou) throws Exception { String sql="select id from policy where name like ? and document like ? and organ like ? ORDER BY pubdata DESC"; PreparedStatement pre = connect.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); pre.setString(1,"%"+mingcheng+"%"); pre.setString(2,"%"+zihao+"%"); pre.setString(3,"%"+jigou+"%"); ResultSet rs = pre.executeQuery(); rs.last(); int rowCount=rs.getRow(); rs.beforeFirst(); Pd_zhengce[] pdStus = new Pd_zhengce[rowCount]; int i=0; while(rs.next()) { pdStus[i]=policy_query(rs.getInt(1)+""); i++; } return pdStus; } }
标签:总结,pre,20,String,getString,rs,sql,2023.4,pdd From: https://www.cnblogs.com/wllovelmbforever/p/17338530.html