বৃহস্পতিবার, ৪ জুন, ২০২০

Getting data from oracle database to android device

 if (Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }
    try {
        Class.forName("oracle.jdbc.driver.OracleDriver");

        String url="jdbc:oracle:thin:@192.168.0.102:1521:orcl";
        String username="hr";
        String password="hr";
        Connection con=DriverManager.getConnection(url, username, password);
        Statement stmt=con.createStatement();

        ResultSet rs = stmt.executeQuery("select first_name from employees");
        StringBuilder stringBuffer = new StringBuilder();
        while (rs.next()) {
            stringBuffer.append(rs.getString(1) + "\n");
        }
        editText.setText(stringBuffer.toString());


        con.close();
} catch (SQLException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }