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

📄 connectiontest.java

📁 在资料浩瀚的互联网中
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*      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 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.simple;import testsuite.BaseTestCase;import java.io.File;import java.io.FileInputStream;import java.io.FileWriter;import java.sql.Connection;import java.sql.DatabaseMetaData;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.sql.Savepoint;import java.sql.Statement;import java.util.Properties;import java.util.StringTokenizer;import com.mysql.jdbc.ConnectionPropertiesTransform;import com.mysql.jdbc.NonRegisteringDriver;import com.mysql.jdbc.SQLError;import com.mysql.jdbc.StringUtils;import com.mysql.jdbc.log.StandardLogger;/** * Tests java.sql.Connection functionality ConnectionTest.java,v 1.1 2002/12/06 * 22:01:05 mmatthew Exp * * @author Mark Matthews */public class ConnectionTest extends BaseTestCase {    /**     * Constructor for ConnectionTest.     *     * @param name the name of the test to run     */    public ConnectionTest(String name) {        super(name);    }    /**     * Runs all test cases in this test suite     *     * @param args     */    public static void main(String[] args) {        junit.textui.TestRunner.run(ConnectionTest.class);    }    /**     * Tests catalog functionality     *     * @throws Exception if an error occurs     */    public void testCatalog() throws Exception {        String currentCatalog = this.conn.getCatalog();        this.conn.setCatalog(currentCatalog);        assertTrue(currentCatalog.equals(this.conn.getCatalog()));    }    /**     * DOCUMENT ME!     *     * @throws Exception DOCUMENT ME!     */    public void testCharsets() throws Exception {        if (versionMeetsMinimum(4, 1)) {            try {                Properties props = new Properties();                props.setProperty("useUnicode", "true");                props.setProperty("characterEncoding", "UTF-8");                Connection utfConn = getConnectionWithProps(props);                this.stmt = utfConn.createStatement();                this.stmt.executeUpdate("DROP TABLE IF EXISTS t1");                //this.stmt.executeUpdate("SET CHARACTER SET latin1");                this.stmt.executeUpdate("CREATE TABLE t1 ("                    + "comment CHAR(32) ASCII NOT NULL,"                    + "koi8_ru_f CHAR(32) CHARACTER SET koi8r NOT NULL"                    + ") CHARSET=latin5");                    				this.stmt.executeUpdate("ALTER TABLE t1 CHANGE comment comment CHAR(32) CHARACTER SET latin2 NOT NULL");				this.stmt.executeUpdate("ALTER TABLE t1 ADD latin5_f CHAR(32) NOT NULL");				this.stmt.executeUpdate("ALTER TABLE t1 CHARSET=latin2");				this.stmt.executeUpdate("ALTER TABLE t1 ADD latin2_f CHAR(32) NOT NULL");				this.stmt.executeUpdate("ALTER TABLE t1 DROP latin2_f, DROP latin5_f");								this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('a','LAT SMALL A')");				/*				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('b','LAT SMALL B')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('c','LAT SMALL C')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('d','LAT SMALL D')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('e','LAT SMALL E')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('f','LAT SMALL F')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('g','LAT SMALL G')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('h','LAT SMALL H')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('i','LAT SMALL I')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('j','LAT SMALL J')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('k','LAT SMALL K')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('l','LAT SMALL L')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('m','LAT SMALL M')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('n','LAT SMALL N')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('o','LAT SMALL O')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('p','LAT SMALL P')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('q','LAT SMALL Q')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('r','LAT SMALL R')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('s','LAT SMALL S')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('t','LAT SMALL T')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('u','LAT SMALL U')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('v','LAT SMALL V')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('w','LAT SMALL W')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('x','LAT SMALL X')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('y','LAT SMALL Y')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('z','LAT SMALL Z')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('A','LAT CAPIT A')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('B','LAT CAPIT B')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('C','LAT CAPIT C')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('D','LAT CAPIT D')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('E','LAT CAPIT E')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('F','LAT CAPIT F')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('G','LAT CAPIT G')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('H','LAT CAPIT H')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('I','LAT CAPIT I')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('J','LAT CAPIT J')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('K','LAT CAPIT K')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('L','LAT CAPIT L')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('M','LAT CAPIT M')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('N','LAT CAPIT N')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('O','LAT CAPIT O')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('P','LAT CAPIT P')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('Q','LAT CAPIT Q')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('R','LAT CAPIT R')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('S','LAT CAPIT S')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('T','LAT CAPIT T')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('U','LAT CAPIT U')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('V','LAT CAPIT V')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('W','LAT CAPIT W')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('X','LAT CAPIT X')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('Y','LAT CAPIT Y')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('Z','LAT CAPIT Z')");				*/								String cyrillicSmallA = "\u0430";				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES ('" + cyrillicSmallA + "','CYR SMALL A')");												/*				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL BE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL VE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL GE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL DE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL IE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL IO')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL ZHE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL ZE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL I')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL KA')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL EL')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL EM')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL EN')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL O')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL PE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL ER')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL ES')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL TE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL U')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL EF')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL HA')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL TSE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL CHE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL SHA')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL SCHA')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL HARD SIGN')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL YERU')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL SOFT SIGN')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL E')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL YU')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR SMALL YA')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT A')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT BE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT VE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT GE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT DE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT IE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT IO')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT ZHE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT ZE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT I')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT KA')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT EL')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT EM')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT EN')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT O')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT PE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT ER')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT ES')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT TE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT U')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT EF')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT HA')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT TSE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT CHE')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT SHA')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT SCHA')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT HARD SIGN')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT YERU')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT SOFT SIGN')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT E')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT YU')");				this.stmt.executeUpdate("INSERT INTO t1 (koi8_ru_f,comment) VALUES (_koi8r'�','CYR CAPIT YA')");				*/								this.stmt.executeUpdate("ALTER TABLE t1 ADD utf8_f CHAR(32) CHARACTER SET utf8 NOT NULL");				this.stmt.executeUpdate("UPDATE t1 SET utf8_f=CONVERT(koi8_ru_f USING utf8)");				this.stmt.executeUpdate("SET CHARACTER SET koi8r");				//this.stmt.executeUpdate("SET CHARACTER SET UTF8");				this.rs = this.stmt.executeQuery("SELECT * FROM t1");								ResultSetMetaData rsmd = this.rs.getMetaData();								int numColumns = rsmd.getColumnCount();								for (int i = 0; i < numColumns; i++) {					System.out.print(rsmd.getColumnName(i + 1));					System.out.print("\t\t");	 				}								System.out.println();								while (this.rs.next()) {					System.out.println(this.rs.getString(1) + "\t\t" + this.rs.getString(2) + "\t\t" + this.rs.getString(3));										if (this.rs.getString(1).equals("CYR SMALL A")) {						this.rs.getString(2);					}				}								System.out.println();								this.stmt.executeUpdate("SET NAMES utf8");				this.rs = this.stmt.executeQuery("SELECT _koi8r 0xC1;");				

⌨️ 快捷键说明

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