Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: Java connect with oracle database

Re: Java connect with oracle database

From: <maaher_at_my-deja.com>
Date: 2000/07/10
Message-ID: <8kbq66$2ek$1@nnrp1.deja.com>#1/1

Zpan,
I strongly recommend NOT to connect as INTERNAL. Especially since you have to put the pwd hard-coded into your source. But, to answer your question the problem is that you try to connect to a table, which is pretty impossible. With JDBC, you connect to a database, as it is shown in the code below.

Have you tried SQLJ yet, it allows you to store the connection properties in a separate file. This prevents users of your application to decompile your source and resolve the username/password combination.

To illustrate my answer, here is some sample code (With JDBC thin drivers) which I used when I was giving a technical session at our company (it was a basic course, I'm not an expert):

import java.sql.*;

public class TestJDBC
{ public static void main(String[] args) throws SQLException
// First, the Oracle Driver is loaded

	{	DriverManager.registerDriver(
			new.oracle.jdbc.driver.OracleDriver());

// then a connection is made to the database
Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@machine_name:1521:database_name","user_name", "password");
// Create the statement object;
Statement stmt = conn.createStatement();
// Parse the statement and get the Resultset...
ResultSet rs = stmt.executeQuery("SELECT <columns> FROM <table>);
// while there are records left
while(rs.next()) {
// Do something with the resultset...
}
// Close the Resultset
rs.close();
// Close the connection
conn.close(); }

}

In article <20000708195346.01791.00001656_at_ng-cn1.aol.com>,   zpan_at_aol.com (ZPAN) wrote:
>
> I have oracle8i and JDK 1.3 installed on a PC with Windows 98 as the  OS.
>
> After I invoked sqlplus under the directory c:\oracle\ and created a  table with

> the following codes,
>
> create table myTable
> (text varchar(20));
>
> insert into myTable values
> ('abc');
>
> Where is this table located?
>
> How can I use Java method getConnection to access this database
 through
> JdbcOdbcDriver?
>
> A java class is located in d:\java\ containing the following
 statement,
>
> connection conn = DriverManager.getConnection("jdbc:odbc:myTable",  "INTERNAL",
> "ORACLE");
>
> I always got an exception.
>
> Could somebody help me this out, and thanks a lot.
>
> Zpan
>
>


Sent via Deja.com http://www.deja.com/
Before you buy. Received on Mon Jul 10 2000 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US