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

📄 connectionregressiontest.java

📁 MySql Java Connector
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2002-2004 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation.  There are special exceptions to the terms and conditions of the GPL  as it is applied to this software. View the full text of the  exception exception in file EXCEPTIONS-CONNECTOR-J in the directory of this  software distribution. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package testsuite.regression;import com.mysql.jdbc.NonRegisteringDriver;import testsuite.BaseTestCase;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Properties;/** * Regression tests for Connections * * @author Mark Matthews * @version $Id: ConnectionRegressionTest.java,v 1.1.2.10 2004/08/09 22:15:12 mmatthew Exp $ */public class ConnectionRegressionTest extends BaseTestCase {    /**     * DOCUMENT ME!     *     * @param name the name of the testcase     */    public ConnectionRegressionTest(String name) {        super(name);    }    /**     * Runs all test cases in this test suite     *     * @param args     */    public static void main(String[] args) {        junit.textui.TestRunner.run(ConnectionRegressionTest.class);    }    /**     * DOCUMENT ME!     *     * @throws Exception ...     */    public void testBug1914() throws Exception {        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), BIGINT)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), BINARY)}"));        System.out.println(this.conn.nativeSQL("{fn convert(foo(a,b,c), BIT)}"));        System.out.println(this.conn.nativeSQL("{fn convert(foo(a,b,c), CHAR)}"));        System.out.println(this.conn.nativeSQL("{fn convert(foo(a,b,c), DATE)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), DECIMAL)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), DOUBLE)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), FLOAT)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), INTEGER)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), LONGVARBINARY)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), LONGVARCHAR)}"));        System.out.println(this.conn.nativeSQL("{fn convert(foo(a,b,c), TIME)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), TIMESTAMP)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), TINYINT)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), VARBINARY)}"));        System.out.println(this.conn.nativeSQL(                "{fn convert(foo(a,b,c), VARCHAR)}"));    }    /**     * Tests fix for BUG#3554 - Not specifying database in URL causes     * MalformedURL exception.     *     * @throws Exception if an error ocurrs.     */    public void testBug3554() throws Exception {        try {            new NonRegisteringDriver().connect("jdbc:mysql://localhost:3306/?user=root&password=root",                new Properties());        } catch (SQLException sqlEx) {            assertTrue(sqlEx.getMessage().indexOf("Malformed") == -1);        }    }    /**     *     *     * @throws Exception ...     */    public void testBug3790() throws Exception {        String field2OldValue = "foo";        String field2NewValue = "bar";        int field1OldValue = 1;        Connection conn1 = null;        Connection conn2 = null;        Statement stmt1 = null;        Statement stmt2 = null;        ResultSet rs2 = null;        Properties props = new Properties();        try {            this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug3790");            this.stmt.executeUpdate(                "CREATE TABLE testBug3790 (field1 INT NOT NULL PRIMARY KEY, field2 VARCHAR(32)) TYPE=InnoDB");            this.stmt.executeUpdate("INSERT INTO testBug3790 VALUES ("                + field1OldValue + ", '" + field2OldValue + "')");            conn1 = getConnectionWithProps(props); // creates a new connection            conn2 = getConnectionWithProps(props); // creates another new connection            conn1.setAutoCommit(false);            conn2.setAutoCommit(false);            stmt1 = conn1.createStatement();            stmt1.executeUpdate("UPDATE testBug3790 SET field2 = '"                + field2NewValue + "' WHERE field1=" + field1OldValue);            conn1.commit();            stmt2 = conn2.createStatement();            rs2 = stmt2.executeQuery("SELECT field1, field2 FROM testBug3790");            assertTrue(rs2.next());            assertTrue(rs2.getInt(1) == field1OldValue);            assertTrue(rs2.getString(2).equals(field2NewValue));        } finally {            this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug3790");            if (rs2 != null) {                rs2.close();            }            if (stmt2 != null) {                stmt2.close();            }            if (stmt1 != null) {                stmt1.close();            }            if (conn1 != null) {                conn1.close();            }            if (conn2 != null) {                conn2.close();            }        }    }    /**     * Tests fix for BUG#4334, port #'s not being picked up      * for failover/autoreconnect.     *      * @throws Exception if an error occurs.     */    public void testBug4334() throws Exception {        if (isAdminConnectionConfigured()) {            Connection adminConnection = null;            try {                adminConnection = getAdminConnection();                int bogusPortNumber = 65534;                NonRegisteringDriver driver = new NonRegisteringDriver();                Properties oldProps = driver.parseURL(BaseTestCase.dbUrl, null);                String host = driver.host(oldProps);                int port = driver.port(oldProps);                String database = oldProps.getProperty("DBNAME");                String user = oldProps.getProperty("user");                String password = oldProps.getProperty("password");                StringBuffer newUrlToTestPortNum = new StringBuffer(                        "jdbc:mysql://");                if (host != null) {                    newUrlToTestPortNum.append(host);                }                newUrlToTestPortNum.append(":").append(port);                newUrlToTestPortNum.append(",");                if (host != null) {                    newUrlToTestPortNum.append(host);                }                newUrlToTestPortNum.append(":").append(bogusPortNumber);                newUrlToTestPortNum.append("/");                if (database != null) {                    newUrlToTestPortNum.append(database);                }                if ((user != null) || (password != null)) {                    newUrlToTestPortNum.append("?");                    if (user != null) {                        newUrlToTestPortNum.append("user=").append(user);                        if (password != null) {                            newUrlToTestPortNum.append("&");                        }                    }                    if (password != null) {                        newUrlToTestPortNum.append("password=").append(password);                    }                }

⌨️ 快捷键说明

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