Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: Connect to local database
You can USE ODBC Administrator to create a alias !
IF alias is POLITE :
by JAVA :
// <URL-userID-password> Per accedere al DB Server Oracle Lite ALIFLY String URL="jdbc:odbc:POLITE"; // Uniform releted Link
String userID="PAOLO"; // UserId String password="KLACID"; // Password
String Query1;
//* Apertura del canale verso DB
database MioDB = new database(URL, userID, password);
//------ Modello
Query1 = "SELECT Descrizione FROM Modello";
//* conto il numero di tuple presenti in Modello
NumDati=MioDB.Conta_Tuple(Query1);
//Title: Demo Conto //Version: 1.0 //Copyright: Copyright (c) 2001 //Author: Paolo Brugnoli //Company: Università la Sapienza //Description:Classe database per apertura canale verso DB Oracle Lite 8i
import java.sql.*;
import java.io.*;
// ************************************************************/ // * Definisco la classe Database che accede al Database e */ // * mi esegue le operazioni di accesso, connessione, query e */ // * update */ // ************************************************************/
class database {
Connection dbconn;
//Il COSTRUTTORE DI CLASSE mi esegue la connessione al database
public database(String URL, String userID, String password) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException ex2) {
System.err.println("Fallita connessione al database. Errore 1"); System.exit(1);
System.err.println("Fallita connessione al database. Errore 2"); ex.printStackTrace(); System.exit(1);
dbconn = DriverManager.getConnection(URL, userID, password); // livello di isolamento dbconn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);}
System.err.println("Fallita connessione al database.."); System.err.println("La fonte ODBC non esiste."); while ( e != null ) { System.err.println("STATO SQL : "+e.getSQLState()); System.err.println("MESSAGGIO : "+e.getMessage()); System.err.println("ERRORE : "+e.getErrorCode()); e = e.getNextException(); } System.exit(1);
System.err.println("Fallita connessione al database. Errore 4"); ex.printStackTrace(); System.exit(1);
//Il metodo ESEGUI_QUERY esegue un comando SQL (select) sul database
//sottostante e ritorna un Result_Set al chiamante;
public ResultSet Esegui_Query(String stringa_SQL) {
Statement statement;
ResultSet result_set = null;
try {
statement = dbconn.createStatement(); result_set = statement.executeQuery(stringa_SQL);}
while ( e != null ) { System.err.println("STATO SQL : "+e.getSQLState()); System.err.println("MESSAGGIO : "+e.getMessage()); System.err.println("ERRORE : "+e.getErrorCode()); e = e.getNextException(); } System.exit(1);
ResultSet result_set = null;
try {
statement = dbconn.createStatement(); result_set = statement.executeQuery(stringa_SQL); while (result_set.next()) { contatore++; }
while ( e != null ) { System.err.println("STATO SQL : "+e.getSQLState()); System.err.println("MESSAGGIO : "+e.getMessage()); System.err.println("ERRORE : "+e.getErrorCode()); e = e.getNextException(); } System.exit(1);
//Il metodo STRUTTURA_QUERY esegue un comando SQL (select) sul database
//sottostante e ritorna la struttura del Result_Set al chiamante;
public synchronized ResultSetMetaData Struttura_Query(String stringa_SQL)
{
Statement statement;
ResultSet result_set = null;
ResultSetMetaData meta_data = null;
try {
statement = dbconn.createStatement(); result_set = statement.executeQuery(stringa_SQL); meta_data = result_set.getMetaData();}
while ( e != null ) { System.err.println("STATO SQL : "+e.getSQLState()); System.err.println("MESSAGGIO : "+e.getMessage()); System.err.println("ERRORE : "+e.getErrorCode()); e = e.getNextException(); } System.exit(1);
statement = dbconn.createStatement(); NumRighe = statement.executeUpdate(stringa_SQL); dbconn.commit();
while ( e != null ) { System.err.println("STATO SQL : "+e.getSQLState()); System.err.println("MESSAGGIO : "+e.getMessage()); System.err.println("ERRORE : "+e.getErrorCode()); e = e.getNextException(); } System.exit(1);
//Il metodo DBchiudi esegue la commit e chiude la connessione al Database
//In questo esempio non viene usato
public void dbchiudi() {
try {
dbconn.commit(); dbconn.close();
while ( e != null ) { System.err.println("STATO SQL : "+e.getSQLState()); System.err.println("MESSAGGIO : "+e.getMessage()); System.err.println("ERRORE : "+e.getErrorCode()); e = e.getNextException(); } System.exit(1);
"Marco de Haan" <ams072_at_wirehub.nl> ha scritto nel messaggio news:981477974.13310_at_newsreader1.wirehub.nl... > How can I make TOAD connect to my local database. > I'm able to connect to remote databases via Internet at the office and to my
> local database by using SCOTT and TIGER. Using the connect-string "2:" > doesn't help either. > > Any suggestions? > >Received on Mon Feb 19 2001 - 15:16:53 CST
![]() |
![]() |