mysql连接在android中无法工作

ql3eal8s  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(228)

我在尝试连接mysql数据库时遇到了这个问题。它告诉我这是错误的,我不知道为什么,因为它没有给我一个具体的错误。
它只是告诉我我在捕获中写了什么。顺便说一句,我使用的是mysql connector/jversion5.1.47。
这是连接代码:

private class GetData extends AsyncTask<String,String,String> {
    String msg = "";
    //JDBC driver name and database URL
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://" +
            DbStrings.DATABASE_URL + "/" +
            DbStrings.DATABASE_NAME;

    @Override
    protected void onPreExecute() {
        ProgressTextView.setText("Connecting to Database...");
    }
    @Override
    protected String doInBackground(String... params) {
        Connection conn = null;
        Statement stmt = null;

        try {
            Class.forName(JDBC_DRIVER);
            conn = DriverManager.getConnection(DB_URL, DbStrings.USERNAME, DbStrings.PASSWORD);

            stmt = conn.createStatement();
            String sql = "SELECT * FROM zimmerstamm";
            ResultSet rs = stmt.executeQuery(sql);

            while (rs.next()) {
                String Bemerkung = rs.getString("Bemerkung");
                Double Zimmer = rs.getDouble("Zimmer");

                fruitsMap.put(Bemerkung, Zimmer);
            }
            msg = "Process complete";

            rs.close();
            stmt.close();
            conn.close();
        } catch (SQLException connError) {
            msg = "An exception was thrwon for JDBC.";
            connError.printStackTrace();
        } catch (ClassNotFoundException e) {
            msg = "And exception was No class found.";
            e.printStackTrace();
        }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题