方法是这样写的:publicbooleanselectProblem(Stringproblem){booleanflag=false;Stringsql="select*fromanswerswhereprolike'%"+this.problem+"%'";try{Class.forName("com.mysql.jd...
方法是这样写的:
public boolean selectProblem(String problem){
boolean flag=false;
String sql = "select * from answers where pro like '%"+this.problem+"%'";
try {
Class.forName("com.mysql.jdbc.Driver");
Conn = DriverManager.getConnection(url);
Stmt = Conn.createStatement();
Rs = Stmt.executeQuery(sql);
flag = true;
} catch (ClassNotFoundException e) {
//
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
}
return flag;
}
测试是这样写的:
import java.sql.SQLException;
public class test {
public static void main(String[] args) throws SQLException {
Answers ans = new Answers();
System.out.println(ans.selectProblem("s"));
while(ans.Rs.next()){
System.out.print("dfad");
System.out.println(ans.Rs.getString("pro"));
}
}
}
运行后只能打印一个true。也就是没有结果集。但是根据图片应该有结果的才对。问题出在哪里??
展开