日期:2014-05-17 浏览次数:20779 次
public String findPlcAmsNetIdByWind_Code(String wind_Code){
List list = new ArrayList();
Session s = null;
try {
s = HibernateUtil.getSession();
Transaction tx=null;
tx=s.beginTransaction();
Query query = s.createQuery("select plcAmsNetId From PlcAmsNetID where wind_Code= ?");
list = query.setParameter(0, wind_Code).list();
tx.commit();
return list.get(0).toString();
} finally {
HibernateUtil.closeSession();
}
}
public String findPlcAmsNetIdByWind_Code_BySql(String wind_Code){
String id = null;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String password = "root";
Statement statement = null;
try {
// 加载驱动程序
Class.forName(driver);
// 连续数据库
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed())
// statement用来执行SQL语句
statement = conn.createStatement();
// 要执行的SQL语句
String sql = "select plcAmsNetId from PlcAmsNetID where wind_Code = '"+wind_Code+"'";
// 结果集
ResultSet rs = statement.executeQuery(sql);
while(rs.next()) {
// 选择sname这列数据
id = rs.getString("plcAmsNetId");
// 首先使用ISO-8859-1字符集将name解码为字节序列并将结果存储新的字节数组中。
// 然后使用GB2312