Re: Version 8.0.19 JDBC & Server problem with view
Posted by: Filipe Silva
Date: May 04, 2020 12:31PM

Hi Dave,

I don't see what could be the problem. The following works just fine:

    public static void main(String[] args) throws Exception {
        Class.forName(Driver.class.getName());

        Connection conn = DriverManager.getConnection("jdbc:mysql:///test", "user", "pwd");
        Statement stmt = conn.createStatement();
        stmt.execute("create table if not exists t1 (a decimal(22,3), b decimal(22,3))");
        stmt.execute("create or replace view v1 as select *, a * b as c from t1");
        stmt.execute("truncate t1");
        stmt.executeUpdate("insert into t1 values (1.1, 2.2), (1000000.1, 2000000.2)");

        System.out.println("table (stmt)");
        ResultSet rs = stmt.executeQuery("select *, a * b as c from t1");
        while (rs.next()) {
            System.out.println(rs.getDouble(1) + " - " + rs.getDouble(2) + " - " + rs.getDouble(3));
        }
        System.out.println("view (stmt)");
        rs = stmt.executeQuery("select * from v1");
        while (rs.next()) {
            System.out.println(rs.getDouble(1) + " - " + rs.getDouble(2) + " - " + rs.getDouble(3));
        }

        System.out.println("table (pstmt)");
        PreparedStatement pstmt = conn.prepareStatement("select *, a * b as c from t1");
        rs = pstmt.executeQuery();
        while (rs.next()) {
            System.out.println(rs.getDouble(1) + " - " + rs.getDouble(2) + " - " + rs.getDouble(3));
        }
        System.out.println("view (pstmt)");
        pstmt = conn.prepareStatement("select *, a * b as c from v1");
        rs = pstmt.executeQuery();
        while (rs.next()) {
            System.out.println(rs.getDouble(1) + " - " + rs.getDouble(2) + " - " + rs.getDouble(3));
        }

        stmt.execute("drop view if exists v1");
        stmt.execute("drop table if exists t1");
        conn.close();
    }

IHTH

Options: ReplyQuote


Subject
Written By
Posted
Re: Version 8.0.19 JDBC & Server problem with view
May 04, 2020 12:31PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.