import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

public class TestClass {

	public static String database_url = "jdbc:oracle:thin:@//oracle11.informatik.uni-goettingen.de:1521/dbis";
	public static String user = "scott";
	public static String pass = "tiger";

	public static void main(String[] args) {
		ResultSet rset = null;
		Connection conn = null;
		try {

			DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
			conn = DriverManager.getConnection(database_url, user, pass);

			Statement stmt = conn.createStatement();

			
			stmt.execute("DROP TABLE TTEST");
			stmt.execute("CREATE TABLE TTEST(A VARCHAR2(4), B Number)");
			stmt.execute("COMMIT");
			stmt.execute("INSERT INTO TTEST VALUES('1BLA',5.7)");
			

			String strSelect = "SELECT * FROM TTEST";
			System.out.println("The SQL query is: " + strSelect);
			System.out.println();

			rset = stmt.executeQuery(strSelect);
			System.out.println("The records selected are:");
			int rowCount = 0;
			while (rset.next()) { // Move the cursor to the next row, return false if no more row
				String first = rset.getString(1);
				int sec = rset.getInt("B");
				System.out.println(first + ", " + sec);
				++rowCount;
			}
			System.out.println("Total number of records = " + rowCount);

			ResultSetMetaData md = rset.getMetaData();
			String columnNames = "";
			for (int i = 1; i <= md.getColumnCount(); i++) {
				columnNames += "\t" + md.getColumnName(i) + " - " + md.getColumnTypeName(i) + "\n";
			}
			System.out.println(columnNames);
		} catch (SQLException ex) {
			ex.printStackTrace();
		} finally {
			try {
				if (rset != null) {
					rset.close();
				}
				if (conn != null) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

	}

}
