⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 safetest.java

📁 第三方的SQL Server and Sybase的jdbc dirver,速度更快
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        } catch (SQLException ex) {//          assertEquals("22001", ex.getSQLState());            assertTrue(ex instanceof DataTruncation);        }        // Close everything        rs.close();        stmt.close();    }*/    /**     * Test for bug [939206] TdsException: can't sent this BigDecimal     */    public void testBigDecimal1() throws Exception {        Statement stmt = con.createStatement();        ResultSet rs = stmt.executeQuery("SELECT @@MAX_PRECISION");        assertTrue(rs.next());        int maxPrecision = rs.getInt(1);        rs.close();        BigDecimal maxval = new BigDecimal("1E+" + maxPrecision);        maxval = maxval.subtract(new BigDecimal(1));        // maxval now = 99999999999999999999999999999999999999        if (maxPrecision > 28) {            stmt.execute("create table #testBigDecimal1 (id int primary key, data01 decimal(38,0), data02 decimal(38,12) null, data03 money)");        } else {            stmt.execute("create table #testBigDecimal1 (id int primary key, data01 decimal(28,0), data02 decimal(28,12) null, data03 money)");        }        PreparedStatement pstmt = con.prepareStatement("insert into #testBigDecimal1 (id, data01, data02, data03) values (?,?,?,?)");        pstmt.setInt(1, 1);        try {            pstmt.setBigDecimal(2, maxval.add(new BigDecimal(1)));            assertTrue(false); // Should fail        } catch (SQLException e) {            // System.out.println(e.getMessage());            // OK Genuinely can't send this one!        }        pstmt.setBigDecimal(2, maxval);        pstmt.setBigDecimal(3, new BigDecimal(1.0 / 3.0)); // Scale > 38        pstmt.setBigDecimal(4, new BigDecimal("12345.56789"));        assertTrue(pstmt.executeUpdate() == 1);        pstmt.close();        rs = stmt.executeQuery("SELECT * FROM #testBigDecimal1");        assertTrue(rs.next());        assertEquals(maxval, rs.getBigDecimal(2));        assertEquals(new BigDecimal("0.333333333333"), rs.getBigDecimal(3)); // Rounded to scale 10        assertEquals(new BigDecimal("12345.5679"), rs.getBigDecimal(4)); // Money has scale of 4        rs.close();        maxval = maxval.negate();        Statement stmt2 = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);        rs = stmt2.executeQuery("SELECT * FROM #testBigDecimal1");        SQLWarning warn = stmt.getWarnings();        while (warn != null) {            System.out.println(warn.getMessage());            warn = warn.getNextWarning();        }        assertTrue(rs.next());        rs.updateBigDecimal("data01", maxval);        rs.updateNull("data02");        rs.updateObject("data03", new BigDecimal("-12345.56789"), 2); // Round to scale 2        rs.updateRow();        rs.close();        stmt2.close();        rs = stmt.executeQuery("SELECT * FROM #testBigDecimal1");        assertTrue(rs.next());        assertEquals(maxval, rs.getBigDecimal(2));        assertEquals(null, rs.getBigDecimal(3));        assertEquals(new BigDecimal("-12345.5700"), rs.getBigDecimal(4));        rs.close();        stmt.close();    }    /**     * Test for bug [963799] float values change when written to the database     */    public void testFloat1() throws Exception {        float value = 2.2f;        Statement stmt = con.createStatement();        stmt.execute("create table #testFloat1 (data decimal(28,10))");        stmt.close();        PreparedStatement pstmt = con.prepareStatement("insert into #testFloat1 (data) values (?)");        pstmt.setFloat(1, value);        assertTrue(pstmt.executeUpdate() == 1);        pstmt.close();        pstmt = con.prepareStatement("select data from #testFloat1");        ResultSet rs = pstmt.executeQuery();        assertTrue(rs.next());        assertTrue(value == rs.getFloat(1));        assertTrue(!rs.next());        pstmt.close();        rs.close();    }    /**     * Test for bug [983561] getDatetimeValue truncates fractional milliseconds     */    public void testDatetimeRounding1() throws Exception {    	long dateTime = 1089297738677L;    	Timestamp value = new Timestamp(dateTime);        Statement stmt = con.createStatement();        stmt.execute("create table #dtr1 (data datetime)");        stmt.close();        PreparedStatement pstmt = con.prepareStatement("insert into #dtr1 (data) values (?)");        pstmt.setTimestamp(1, value);        assertTrue(pstmt.executeUpdate() == 1);        pstmt.close();        pstmt = con.prepareStatement("select data from #dtr1");        ResultSet rs = pstmt.executeQuery();        assertTrue(rs.next());        assertTrue(value.equals(rs.getTimestamp(1)));        assertTrue(!rs.next());        pstmt.close();        rs.close();    }    public void testSocketConcurrency1() {        final Connection con = this.con;        final int threadCount = 10, loopCount = 10;        final Vector errors = new Vector();//        DriverManager.setLogStream(System.out);        // Create a huge query        StringBuffer queryBuffer = new StringBuffer(4100);        queryBuffer.append("SELECT '");        while (queryBuffer.length() < 2000) {            queryBuffer.append("0123456789");        }        queryBuffer.append("' AS value1, '");        while (queryBuffer.length() < 4000) {            queryBuffer.append("9876543210");        }        queryBuffer.append("' AS value2");        final String query = queryBuffer.toString();        Thread  heavyThreads[] = new Thread[threadCount],                lightThreads[] = new Thread[threadCount];        // Create threadCount heavy threads        for (int i = 0; i < threadCount; i++) {            heavyThreads[i] = new Thread() {                public void run() {                    try {                        Statement stmt = con.createStatement();                        for (int i = 0; i < loopCount; i++) {                            stmt.execute(query);                        }                        stmt.close();                    } catch (SQLException ex) {                        ex.printStackTrace();                        errors.add(ex);                    }                }            };        }        // Create threadCount light threads        for (int i = 0; i < threadCount; i++) {            lightThreads[i] = new Thread() {                public void run() {                    try { sleep(100); } catch (InterruptedException ex) {}                    try {                        Statement stmt = con.createStatement();                        for (int i = 0; i < loopCount; i++) {                            stmt.execute("SELECT 1");                        }                        stmt.close();                    } catch (Exception ex) {                        ex.printStackTrace();                        errors.add(ex);                    }                }            };        }        for (int i = 0; i < threadCount; i++) {            heavyThreads[i].start();            lightThreads[i].start();        }        for (int i = 0; i < threadCount; i++) {            try { heavyThreads[i].join(); } catch (InterruptedException ex) {}            try { lightThreads[i].join(); } catch (InterruptedException ex) {}        }        assertEquals(0, errors.size());    }    public void testSocketConcurrency2() {        final Connection con = this.con;        final int threadCount = 10, loopCount = 10;        final Vector errors = new Vector();//        DriverManager.setLogStream(System.out);        // Create a huge query        StringBuffer valueBuffer = new StringBuffer(4000);        while (valueBuffer.length() < 4000) {            valueBuffer.append("0123456789");        }        final String value = valueBuffer.toString();        Thread  heavyThreads[] = new Thread[threadCount],                lightThreads[] = new Thread[threadCount];        // Create threadCount heavy threads        for (int i = 0; i < threadCount; i++) {            heavyThreads[i] = new Thread() {                public void run() {                    try {                        PreparedStatement pstmt = con.prepareStatement(                                "SELECT ? AS value1, ? AS value2");                        pstmt.setString(1, value);                        pstmt.setString(2, value);                        for (int i = 0; i < loopCount; i++) {                            pstmt.execute();                        }                        pstmt.close();                    } catch (SQLException ex) {                        ex.printStackTrace();                        errors.add(ex);                    }                }            };        }        // Create threadCount light threads        for (int i = 0; i < threadCount; i++) {            lightThreads[i] = new Thread() {                public void run() {                    try { sleep(100); } catch (InterruptedException ex) {}                    try {                        Statement stmt = con.createStatement();                        for (int i = 0; i < loopCount; i++) {                            stmt.execute("SELECT 1");                        }                        stmt.close();                    } catch (Exception ex) {                        ex.printStackTrace();                        errors.add(ex);                    }                }            };        }        for (int i = 0; i < threadCount; i++) {            heavyThreads[i].start();            lightThreads[i].start();        }        for (int i = 0; i < threadCount; i++) {            try { heavyThreads[i].join(); } catch (InterruptedException ex) {}            try { lightThreads[i].join(); } catch (InterruptedException ex) {}        }        assertEquals(0, errors.size());    }    public void testSocketConcurrency3() {        final Connection con = this.con;        final int threadCount = 10, loopCount = 10;        final Vector errors = new Vector();//        DriverManager.setLogStream(System.out);        // Create a huge query        StringBuffer valueBuffer = new StringBuffer(4000);        while (valueBuffer.length() < 4000) {            valueBuffer.append("0123456789");        }        final String value = valueBuffer.toString();        Thread  heavyThreads[] = new Thread[threadCount],                lightThreads[] = new Thread[threadCount];        // Create threadCount heavy threads        for (int i = 0; i < threadCount; i++) {            heavyThreads[i] = new Thread() {                public void run() {                    try {                        PreparedStatement pstmt = con.prepareStatement(                                "SELECT ? AS value1, ? AS value2");                        pstmt.setString(1, value);                        pstmt.setString(2, value);                        for (int i = 0; i < loopCount; i++) {                            pstmt.execute();                        }                        pstmt.close();                    } catch (SQLException ex) {                        ex.printStackTrace();                        errors.add(ex);                    }                }            };        }        // Create threadCount light threads        for (int i = 0; i < threadCount; i++) {            lightThreads[i] = new Thread() {                public void run() {                    try { sleep(100); } catch (InterruptedException ex) {}                    try {                        CallableStatement cstmt = con.prepareCall("sp_who");                        for (int i = 0; i < loopCount; i++) {                            cstmt.execute();                        }                        cstmt.close();                    } catch (Exception ex) {                        ex.printStackTrace();                        errors.add(ex);                    }                }            };        }        for (int i = 0; i < threadCount; i++) {            heavyThreads[i].start();            lightThreads[i].start();        }        for (int i = 0; i < threadCount; i++) {            try { heavyThreads[i].join(); } catch (InterruptedException ex) {}            try { lightThreads[i].join(); } catch (InterruptedException ex) {}        }        assertEquals(0, errors.size());    }    /**     * Test running SELECT queries on one <code>Statement</code> at the same     * time as <code>cancel()</code> is called on a concurrent     * <code>Statement</code>.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -