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

📄 testexceptionmethods.java

📁 java 数据库 功能强大 效率高 SmallSQL Database is a free DBMS library for the Java(tm) platform. It runs on
💻 JAVA
字号:
/* =============================================================
 * SmallSQL : a free Java DBMS library for the Java(tm) platform
 * =============================================================
 *
 * (C) Copyright 2004-2007, by Volker Berlin.
 *
 * Project Info:  http://www.smallsql.de/
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library 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 Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * ---------------
 * TestExceptionMethods.java
 * ---------------
 * Author: Volker Berlin
 * 
 * Created on 02.03.2005
 */
package smallsql.junit;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author Volker Berlin
 */
public class TestExceptionMethods extends BasicTestCase{

    public void testForwardOnly() throws Exception{
        Connection con = AllTests.getConnection();
        try{
            con.createStatement().execute("Create Table ExceptionMethods(v varchar(30))");

            con.createStatement().execute("Insert Into ExceptionMethods(v) Values('qwert')");

            ResultSet rs = con.createStatement().executeQuery("Select * from ExceptionMethods");
            assertEquals(true, rs.next());

            try{
                rs.isBeforeFirst();
                fail("SQLException 'ResultSet is forward only' should be throw");
            }catch(SQLException e){
                assertSQLException("01000", 0, e);
            }

            try{
                rs.isFirst();
                fail("SQLException 'ResultSet is forward only' should be throw");
            }catch(SQLException e){
                assertSQLException("01000", 0, e);
            }

            try{
                rs.first();
                fail("SQLException 'ResultSet is forward only' should be throw");
            }catch(SQLException e){
                assertSQLException("01000", 0, e);
            }

            try{
                rs.previous();
                fail("SQLException 'ResultSet is forward only' should be throw");
            }catch(SQLException e){
                assertSQLException("01000", 0, e);
            }

            try{
                rs.last();
                fail("SQLException 'ResultSet is forward only' should be throw");
            }catch(SQLException e){
                assertSQLException("01000", 0, e);
            }

            try{
                rs.isLast();
                fail("SQLException 'ResultSet is forward only' should be throw");
            }catch(SQLException e){
                assertSQLException("01000", 0, e);
            }

            try{
                rs.isAfterLast();
                fail("SQLException 'ResultSet is forward only' should be throw");
            }catch(SQLException e){
                assertSQLException("01000", 0, e);
            }

            try{
                rs.afterLast();
                fail("SQLException 'ResultSet is forward only' should be throw");
            }catch(SQLException e){
                assertSQLException("01000", 0, e);
            }

            try{
                rs.absolute(1);
                fail("SQLException 'ResultSet is forward only' should be throw");
            }catch(SQLException e){
                assertSQLException("01000", 0, e);
            }

            try{
                rs.relative(1);
                fail("SQLException 'ResultSet is forward only' should be throw");
            }catch(SQLException e){
                assertSQLException("01000", 0, e);
            }
        }finally{
            dropTable(con, "ExceptionMethods");
        }
    }


    public void testGetConnection() throws Exception{
        Connection con;
        try{
            con = DriverManager.getConnection(AllTests.JDBC_URL + "?abc");
            con.close();
            fail("IllegalArgumentException should be throw");
        }catch(IllegalArgumentException ex){
            /* is OK */
        }
        con = DriverManager.getConnection(AllTests.JDBC_URL + "? ");
        con.close();

        con = DriverManager.getConnection(AllTests.JDBC_URL + "?a=b; ; c=d  ; e = f; ; ");
        con.close();

    }

}

⌨️ 快捷键说明

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