Home » Developer & Programmer » JDeveloper, Java & XML » how to connect oracle 11g from netbeans 7
how to connect oracle 11g from netbeans 7 [message #536406] Tue, 20 December 2011 14:24 Go to next message
comptech
Messages: 14
Registered: December 2011
Junior Member
hi
i want to coonect oracle with oci from netbeans and write this code but i couldnt. please guide me:

import java.sql.*;

class OraOci {
public static void main (String args []) throws SQLException
{
try {
Class.forName ("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@hostname_orcl", "system", "9898");
// or oci7 @TNSNames_Entry, userid, password

Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
while (rset.next())
System.out.println (rset.getString(1)); // Print col 1
stmt.close();
}
}
Re: how to connect oracle 11g from netbeans 7 [message #536455 is a reply to message #536406] Wed, 21 December 2011 01:11 Go to previous messageGo to next message
Littlefoot
Messages: 21561
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I never did that, but - what happened when you executed that code? Any error? If so, which one? Could you copy/paste code execution into your next message?
reply [message #536575 is a reply to message #536406] Wed, 21 December 2011 11:23 Go to previous messageGo to next message
comptech
Messages: 14
Registered: December 2011
Junior Member
yes message is:

run:
java.lang.NoClassDefFoundError: oraoci/OraOci
Caused by: java.lang.ClassNotFoundException: oraoci.OraOci
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: oraoci.OraOci. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Re: reply [message #536577 is a reply to message #536575] Wed, 21 December 2011 11:30 Go to previous messageGo to next message
BlackSwan
Messages: 26703
Registered: January 2009
Location: SoCal
Senior Member
bcm@bcm-laptop:~$ cat Conn.java
import java.sql.*;
class Conn {
  public static void main (String[] args) throws Exception
  {
   Class.forName ("oracle.jdbc.OracleDriver");

   Connection conn = DriverManager.getConnection
     ("jdbc:oracle:thin:@//localhost:1521/v112", "scott", "tiger");
                        // @//machineName:port/SID,   userid,  password
   try {
     Statement stmt = conn.createStatement();
     try {
       ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
       try {
         while (rset.next())
           System.out.println (rset.getString(1));   // Print col 1
       } 
       finally {
          try { rset.close(); } catch (Exception ignore) {}
       }
     } 
     finally {
       try { stmt.close(); } catch (Exception ignore) {}
     }
   } 
   finally {
     try { conn.close(); } catch (Exception ignore) {}
   }
  }
}
bcm@bcm-laptop:~$ javac Conn.java
bcm@bcm-laptop:~$ export CLASSPATH=/u01/app/oracle/product/11.2.0/dbhome_1/owb/wf/lib/ojdbc14.jar:.
bcm@bcm-laptop:~$ java Conn
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE	11.2.0.1.0	Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
bcm@bcm-laptop:~$
Re: reply [message #536765 is a reply to message #536577] Thu, 22 December 2011 11:41 Go to previous messageGo to next message
comptech
Messages: 14
Registered: December 2011
Junior Member
dear freiend i want to connect oracle oci.please put that codes
Re: reply [message #536766 is a reply to message #536765] Thu, 22 December 2011 13:04 Go to previous messageGo to next message
Michel Cadot
Messages: 67135
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Replace "thin" by "oci" in the previous code.

Regards
Michel
re [message #536874 is a reply to message #536406] Fri, 23 December 2011 10:53 Go to previous messageGo to next message
comptech
Messages: 14
Registered: December 2011
Junior Member
i do that and message is:

run:
Exception in thread "main" java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at rezajavaapplication7.Conn.main(Conn.java:15)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Re: re [message #536876 is a reply to message #536874] Fri, 23 December 2011 11:31 Go to previous messageGo to next message
Michel Cadot
Messages: 67135
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Did you install the Oracle client?

Regards
Michel
Re: re [message #536884 is a reply to message #536876] Fri, 23 December 2011 12:51 Go to previous messageGo to next message
comptech
Messages: 14
Registered: December 2011
Junior Member
no i just create user and grant to him.how to do this job?
Re: re [message #536886 is a reply to message #536884] Fri, 23 December 2011 12:56 Go to previous messageGo to next message
Michel Cadot
Messages: 67135
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You have to install the Oracle client if you want to use the OCI driver.

Regards
Michel
Re: re [message #536893 is a reply to message #536886] Fri, 23 December 2011 14:03 Go to previous messageGo to next message
comptech
Messages: 14
Registered: December 2011
Junior Member
thank you. i underestand where the problem. i didnt add jdbc library
Re: re [message #536895 is a reply to message #536893] Fri, 23 December 2011 14:26 Go to previous message
Michel Cadot
Messages: 67135
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Thanks for the feedback.

Regards
Michel
Previous Topic: ora 29531 Why?
Next Topic: make right to left an adf page in jdeveloper
Goto Forum:
  


Current Time: Fri May 29 09:56:03 CDT 2020