- 论坛徽章:
- 0
|
Select操作请教!
谢谢,我已经解决了,可以提供代码给大家看一下,并请给予指点!
- 代码如下:
- public boolean executeQuery(String str1,String str2)
- {
- rs = null;
-
- try{
- java.sql.PreparedStatement ps;
- //创建连接
- conn = DriverManager.getConnection(ConnStr);
- Statement stmt = conn.createStatement();
- rs = stmt.executeQuery("select * from faq");
-
- while (rs.next()){
- String info1 = rs.getString(1);//获取第一个字段值
- String info2 = rs.getString(2);//获取第二个字段值
- if((info1.compareTo(str1)==0)&&(info2.compareTo(str2)==0)){
- System.out.println(info1+""+info2+"The success!");
- break;
- }
- }
- conn.commit();
- conn.close();
- System.out.println("exec ok!");
- }
- catch(SQLException e)
- {
- System.err.println("The fail!");
- return false;
- }
- return true;
- }
复制代码 |
|