当前位置:网站首页>Error in Android connection database query statement

Error in Android connection database query statement

2022-06-24 19:51:00 CSDN Q & A

The phenomenon and background of the problem

Error in Android connection database query statement

        Class.forName(driverName); //jdk edition 6.0 This sentence can be omitted from the above         con= DriverManager.getConnection(dbURL,userName,userPwd);        String sql="select * from Manager where _id = "+_id;        Statement st=con.createStatement();        if(st.executeQuery(sql)!=null)        {            Log.d(" The connection fails ","?");        }        ResultSet rs=st.executeQuery(sql);        Log.d(" Inquire about id success ",rs.getString("_id"));        while(rs.next()){            if(rs.getString("_id").equals(_id)&&rs.getString("psd").equals(password)){                result="1";                Log.d(" Login successful ","success");                break;

}

Operation results and error reporting contents

Test connection statement yes , The query statement is not empty , But the user name cannot be found , The second problem log doesn't come out

img


img

My solution ideas and tried methods

Changed the database _id data type , The test data I use is 01
Also try adding single quotes

What I want to achieve

Want to know why the query statement is wrong




Take the answer :
if(st.executeQuery(sql)!=null)        {            Log.d(" The connection fails ","?");        } Change it to       try {            if(con== null || con.isClosed()) {                conn = DriverManager.getConnection(url, user, password);            }        }catch(Exception ex) {            ex.printStackTrace();        }

原网站

版权声明
本文为[CSDN Q & A]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202142226269106.html