Android连接MySQL数据库
public static boolean login(String username, String password) { boolean b = false; try { Connection con= DriverManager.getConnection(URL,USER,PASSWORD); Statement stam = con.createStatement(); // con = this.getConn(); con.setAutoCommit(false); //由当前数据库连接生成一个数据库操作对象 stam = (Statement) con.createStatement(); String sql = String.format( "SELECT * FROM user where username='%s' and password='%s'", username, password); //查询的结果存到了resultset中 ResultSet rs = stam.executeQuery(sql); con.commit(); b = rs.next(); } catch (SQLException e) { e.printStackTrace(); } return b; }
b的返回值总是false,求大神帮帮忙!在此谢过了!!!