Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

jdbc sample for oracle doesnot work

4 views
Skip to first unread message

Michael Raschepkin

unread,
Sep 14, 1999, 3:00:00 AM9/14/99
to
Hello

There is a sample from distributive of Oracle Client
\orant\jdbc\samples\thin\Employee.java.

I modified it to: (two System.out.println() was added)


// You need to import the java.sql package to use JDBC
import java.sql.*;

class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as <host>:<port>:<sid>. The example uses the short cut syntax.
System.out.println("1");
Connection conn =
DriverManager.getConnection
("jdbc:oracle:thin:@myserverhostname:1521:mysid",
"user", "password");
System.out.println("2");

// Create a Statement
Statement stmt = conn.createStatement ();

// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");

// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}

myserverhost, mysid, user and password -- all was changed to real values.

It was successful compiled.

When I run it it writes 1 on my screen and goes out (there are no any exceptions
or 2 on the screen).
When i write the wrong password the situation is the same, but when i write
wrong servername or user it writes 1 and (as I should expect) some exceptions:
Exception in thread "main" java.sql.SQLException: ORA-01017: invalid username/pa

ssword; logon denied

at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:181)
at oracle.jdbc.ttc7.O3log.receive1st(O3log.java, Compiled Code)
at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:163)
at
oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:103) etc

I use WinNT 4 as the client,
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit),
Oracle 8.0.5 (on Solaris).

How to connect to Oracle database?

--
---------------
good luck!
Michael
---

0 new messages