001: /*
002:
003: Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.statementJdbc30
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyTesting.functionTests.tests.jdbcapi;
023:
024: import java.sql.Connection;
025: import java.sql.ResultSet;
026: import java.sql.SQLException;
027: import java.sql.Statement;
028:
029: import org.apache.derby.tools.ij;
030: import org.apache.derby.iapi.reference.JDBC30Translation;
031:
032: /**
033: * Test of additional methods in JDBC3.0 methods in statement class.
034: *
035: */
036:
037: public class statementJdbc30 {
038:
039: public static void main(String[] args) {
040: Connection con;
041: ResultSet rs;
042: Statement stmt;
043:
044: System.out.println("Test statementJdbc30 starting");
045:
046: try {
047: // use the ij utility to read the property file and
048: // make the initial connection.
049: ij.getPropertyArg(args);
050: con = ij.startJBMS();
051:
052: stmt = con.createStatement();
053:
054: //create a table, insert a row, do a select from the table,
055: stmt
056: .execute("create table tab1 (i int, s smallint, r real)");
057: stmt.executeUpdate("insert into tab1 values(1, 2, 3.1)");
058:
059: // read the data just for the heck of it
060: rs = stmt.executeQuery("select * from tab1");
061: rs.next();
062:
063: System.out.println("trying stmt.getMoreResults(int) :");
064: stmt.getMoreResults(JDBC30Translation.CLOSE_CURRENT_RESULT);
065:
066: System.out
067: .println("trying stmt.executeUpdate(String, int) :");
068: stmt.executeUpdate("insert into tab1 values(2, 3, 4.1)",
069: JDBC30Translation.NO_GENERATED_KEYS);
070:
071: System.out
072: .println("trying stmt.executeUpdate(String, int[]) :");
073: int[] columnIndexes = new int[2];
074: columnIndexes[0] = 1;
075: columnIndexes[1] = 2;
076: try {
077: stmt.executeUpdate(
078: "insert into tab1 values(2, 3, 4.1)",
079: columnIndexes);
080: } catch (SQLException ex) {
081: dumpExpectedSQLExceptions(ex);
082: }
083:
084: System.out
085: .println("trying stmt.executeUpdate(String, String[]) :");
086: String[] columnNames = new String[2];
087: columnNames[0] = "I";
088: columnNames[1] = "S";
089: try {
090: stmt.executeUpdate(
091: "insert into tab1 values(2, 3, 4.1)",
092: columnNames);
093: } catch (SQLException ex) {
094: dumpExpectedSQLExceptions(ex);
095: }
096:
097: System.out.println("trying stmt.execute(String, int) :");
098: stmt.execute("select * from tab1",
099: JDBC30Translation.NO_GENERATED_KEYS);
100:
101: System.out.println("trying stmt.execute(String, int[]) :");
102: try {
103: stmt.execute("insert into tab1 values(2, 3, 4.1)",
104: columnIndexes);
105: } catch (SQLException ex) {
106: dumpExpectedSQLExceptions(ex);
107: }
108:
109: System.out
110: .println("trying stmt.execute(String, String[]) :");
111: try {
112: stmt.execute("insert into tab1 values(2, 3, 4.1)",
113: columnNames);
114: } catch (SQLException ex) {
115: dumpExpectedSQLExceptions(ex);
116: }
117:
118: System.out
119: .println("trying stmt.getResultSetHoldability() :");
120: stmt.getResultSetHoldability();
121:
122: System.out.println("trying stmt.getGeneratedKeys() :");
123: stmt.getGeneratedKeys();
124:
125: rs.close();
126: stmt.close();
127: con.close();
128:
129: } catch (SQLException e) {
130: System.out.println("Expected : " + e.getMessage());
131: } catch (Throwable e) {
132: System.out.println("FAIL -- unexpected exception: " + e);
133: e.printStackTrace();
134: }
135:
136: System.out.println("Test statementJdbc30 finished");
137: }
138:
139: public static void dumpExpectedSQLExceptions(SQLException se) {
140: System.out.println("PASS -- expected exception");
141: while (se != null) {
142: System.out.println("SQLSTATE(" + se.getSQLState() + "): "
143: + se);
144: se = se.getNextException();
145: }
146: }
147: }
|