开发者

android making a mysql connection and getting some data back

开发者 https://www.devze.com 2023-02-15 05:29 出处:网络
I need to make a mysql connection and get some data back. I can do this in Java using this code try{ String username;

I need to make a mysql connection and get some data back. I can do this in Java using this code

        try{
                     String username;
                      String password;
                      username = tf.getText();
                      password = tf2.getText();
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                    Connection con = DriverManager.getConnection("jdbc:mysql://188.181.248.30:3306/test","simon","123");
                    int counter = 0;
                    try{
                      Statement st = con.createStatement();
                      ResultSet res = st.executeQuery("SELECT * FROM  KUNDER");
                   //  System.out.println("NAVN: " + "\t" + "KREDIT: ");
                      while (res.next() && counter ==0) {
                        String i = res.getString("NAVN");
                        String s = res.getString("KREDIT");
                        System.out.println(i + "\t\t" + s);
                        if(username.equals(i)){
                            //stf3.setText("login true");
                    //      System.out.println("username og navn passer sammen et sted");
                            if(password.equals(s)){
                                tf3.setText("login true1");
                    //      System.out.println("pass og navn passer sammen");   
                            counter=10;
                            }else{
                                    tf3.setText("login fail");
                                    counter =10;

                            }
                            }else{
                                //tf3.setText("login fail");
                            }
                      }
                      con.close();
                    }
                    catch (SQLException s){
  开发者_如何学编程                      tf3.setText("sql fail");
                      System.out.println("SQL code does not execute.");
                    }    

But when I try to do this in Android, I get an error when trying to launch the app saying:

[2011-03-06 00:30:04 - sqlLite] Conversion to Dalvik format failed with error 1

I don't know what to do right now. I been reading around the net, but can't find anything I can get working.


Do not access MySQL from Android via JDBC. Wrap your MySQL database in a Web service, and access the Web service from Android.


You might also want to read: Why is the paradigm of "Direct Database Connection" not welcomed by Android Platform?

0

精彩评论

暂无评论...
验证码 换一张
取 消