javatools.database
Class OracleDatabase

java.lang.Object
  extended by javatools.database.Database
      extended by javatools.database.OracleDatabase

public class OracleDatabase
extends Database

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). The class OracleDatabase implements the Database-interface for an Oracle SQL data base. Make sure that the file "classes12.jar" of the Oracle distribution is in the classpath. When using Eclipse, add the file via Project ->Properties ->JavaBuildPath ->Libraries ->ExternalJARFile.
Example:

     Database d=new OracleDatabase("user","password");
     d.queryColumn("SELECT foodname FROM food WHERE origin=\"Italy\"")
     -> [ "Pizza Romana", "Spaghetti alla Bolognese", "Saltimbocca"]
     Database.describe(d.query("SELECT * FROM food WHERE origin=\"Italy\"")
     -> foodname |origin  |calories |
        ------------------------------
        Pizza Rom|Italy   |10000    |
        Spaghetti|Italy   |8000     |
        Saltimboc|Italy   |8000     |
This class also provides SQL datatypes (extensions of SQLType.java) that behave according to the conventions of Oracle. For example, the ANSI SQL datatype BOOLEAN is mapped to NUMBER(1). Furthermore, VARCHAR string literals print inner quotes as doublequotes.

Oracle (and only Oracle!) often complains "ORA-01000: maximum open cursors exceeded". This does not necessarily mean that the maximum number of open cursors is exceeded. It can also mean that your SQL statement has an invalid character. Check your SQL statements carefully. If the statements are OK, try the following:

The simplest solution, though, is to use another database. Postgres and MySQL can be downloaded for free, PostgresDatabase.java and MySQLDatabase.java provide the respective Java-adapters.


Nested Class Summary
static class OracleDatabase.Bigint
           
static class OracleDatabase.Bool
           
static class OracleDatabase.Varchar
           
 
Nested classes/interfaces inherited from class javatools.database.Database
Database.CommitTransactionSQLException, Database.ConnectionBrokenSQLException, Database.InitTransactionSQLException, Database.Inserter, Database.RollbackTransactionSQLException, Database.StartAutoCommitSQLException, Database.TransactionSQLException
 
Field Summary
static OracleDatabase.Bigint bigint
           
static OracleDatabase.Bool bool
           
static OracleDatabase.Varchar varchar
           
 
Fields inherited from class javatools.database.Database
java2SQL, MINCOLUMNWIDTH, SCREENWIDTH, type2SQL
 
Constructor Summary
OracleDatabase()
          Constructs a non-functional OracleDatabase for use of getSQLType
OracleDatabase(java.lang.String user, java.lang.String password)
          Constructs a new OracleDatabase from a user and a password on the localhost
OracleDatabase(java.lang.String user, java.lang.String password, java.lang.String host)
          Constructs a new OracleDatabase from a user, a password and a host
OracleDatabase(java.lang.String user, java.lang.String password, java.lang.String host, java.lang.String port)
          Constructs a new OracleDatabase from a user, a password and a host
OracleDatabase(java.lang.String user, java.lang.String password, java.lang.String host, java.lang.String port, java.lang.String inst)
          Constructs a new OracleDatabase from a user, a password and a host
 
Method Summary
 void connect()
          connects to the database specified
 boolean connected()
          Checks whether the connection to the database is still alive
 boolean jarAvailable()
          TRUE if the required JAR is there
 java.lang.String limit(java.lang.String sql, int n)
          Makes an SQL query limited to n results
static void main(java.lang.String[] args)
           
 void resetConnection()
          Deprecated. replaced by Database.reconnect()
 
Methods inherited from class javatools.database.Database
autoincrementColumn, cast, close, close, close, close, createIndex, createIndexCommand, createIndices, createPrimaryKey, createTable, createView, describe, describe, dumpCSV, dumpQueryAsCSV, endTransaction, endTransaction, executeUpdate, exists, existsTable, finalize, flush, format, formatNullToNull, getConnection, getFetchsize, getResultSetConcurrency, getResultSetType, getSQLStmntIFNULL, getSQLType, getSQLType, getSQLType, getValidityCheckTimeout, indexName, isAutoReconnectingOnSelect, isAutoReconnectingOnUpdate, loadCSV, lockTableReadAccess, lockTableWriteAccess, makeCSV, makeCSVForQuery, newInserter, newInserter, newInserter, offset, query, query, query, query, queryValue, reconnect, releaseLocksAndEndTransaction, resetTransaction, runInterface, setAutoReconnectOnSelect, setAutoReconnectOnUpdate, setFetchsize, setResultSetConcurrency, setResultSetType, setValidityCheckTimeout, startTransaction, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

varchar

public static OracleDatabase.Varchar varchar

bool

public static OracleDatabase.Bool bool

bigint

public static OracleDatabase.Bigint bigint
Constructor Detail

OracleDatabase

public OracleDatabase()
Constructs a non-functional OracleDatabase for use of getSQLType


OracleDatabase

public OracleDatabase(java.lang.String user,
                      java.lang.String password,
                      java.lang.String host)
               throws java.lang.InstantiationException,
                      java.lang.IllegalAccessException,
                      java.lang.ClassNotFoundException,
                      java.sql.SQLException
Constructs a new OracleDatabase from a user, a password and a host

Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.sql.SQLException

OracleDatabase

public OracleDatabase(java.lang.String user,
                      java.lang.String password,
                      java.lang.String host,
                      java.lang.String port)
               throws java.lang.InstantiationException,
                      java.lang.IllegalAccessException,
                      java.lang.ClassNotFoundException,
                      java.sql.SQLException
Constructs a new OracleDatabase from a user, a password and a host

Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException
java.sql.SQLException

OracleDatabase

public OracleDatabase(java.lang.String user,
                      java.lang.String password,
                      java.lang.String host,
                      java.lang.String port,
                      java.lang.String inst)
               throws java.lang.InstantiationException,
                      java.lang.IllegalAccessException,
                      java.lang.ClassNotFoundException,
                      java.sql.SQLException
Constructs a new OracleDatabase from a user, a password and a host

Throws:
java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
java.sql.SQLException

OracleDatabase

public OracleDatabase(java.lang.String user,
                      java.lang.String password)
               throws java.lang.Exception
Constructs a new OracleDatabase from a user and a password on the localhost

Throws:
java.lang.Exception
Method Detail

resetConnection

@Deprecated
public void resetConnection()
                     throws java.sql.SQLException
Deprecated. replaced by Database.reconnect()

Resets the connection.

Throws:
java.sql.SQLException

connect

public void connect()
             throws java.sql.SQLException
connects to the database specified

Specified by:
connect in class Database
Throws:
java.sql.SQLException

limit

public java.lang.String limit(java.lang.String sql,
                              int n)
Makes an SQL query limited to n results

Overrides:
limit in class Database

jarAvailable

public boolean jarAvailable()
Description copied from class: Database
TRUE if the required JAR is there

Overrides:
jarAvailable in class Database

connected

public boolean connected()
Checks whether the connection to the database is still alive

Overrides:
connected in class Database

main

public static void main(java.lang.String[] args)