为什么使用JDBC的MYSQL Server无法在Android上使用?

时间:2019-07-14 16:29:27

标签: java android mysql jdbc

我正在为我的业务项目创建一个程序,并且我想使用MySQL Connector驱动器与MYSQL插件一起使用,以便该项目与桌面一起工作。 这是我的尝试,解决方案在哪里。

package com.example.shop;

import android.util.Log;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * Created by Loving on 27.04.2018.
 */
public class JdbcPlainTest {
    private static final String DB_URL = "jdbc:mysql://198.162.43.52:3306/uzaart_teda";
    private static final String USER_NAME = "user";
    private static final String PASSWORD = "12345";

    private Connection createConnection() {
        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(DB_URL, USER_NAME, PASSWORD);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            Log.v("MyLog","Hato1");
        } catch (SQLException e) {
            Log.v("MyLog","Hato2");
            e.printStackTrace();
        }
        return conn;
    }
        public void ProductsSelectQuery() throws SQLException {

        ResultSet rs = null;
            Statement stmt = null;
            Connection conn = createConnection();
            try {
                stmt = conn.createStatement();
                rs = stmt.executeQuery("SELECT `sana` FROM `asos`");
                while (rs.next()) {
                    Log.v("MyLog",rs.getString("sana"));
                }
            } catch (SQLException e) {
                Log.v("MyLog","Bazada Hato ");
                //e.printStackTrace();
            }
            finally {
               try {
                    rs.close();
                    stmt.close();
                    conn.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
    }
}

这是工人阶级。

jdbcPlainTest=new JdbcPlainTest();
        try {
            jdbcPlainTest.ProductsSelectQuery();
        } catch (SQLException e) {
            e.printStackTrace();
            Log.v(TAG,"Hato");
        }

07-14 20:39:02.426 25435-25435 / com.example.shop V / MyLog:Hato2

0 个答案:

没有答案