Click here to Skip to main content
12,891,469 members (51,280 online)
Rate this:
Please Sign up or sign in to vote.
See more: Java Oracle
Hello everyone,

I am developing Java project with netbeans. I completed all the parts(GUI and java code) I want to connect to database keep some information in database for example I want to add new user via textbox to database. However I couldnt Connect it.
Here is my code guys please help me that project is so important for me.

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
try {
    Connection con=null;
    Statement s=con.createStatement();
    s.execute("INSERT INTO E_USER VALUES(((u_name,u_pass,u_role)('"+txtAddUserName.getText()+"','"+txtAddUserPassWord.getText()+"','"+cmbAddUserRole.getSelectedItem().toString()+"')");
 catch(ClassNotFoundException | SQLException e){}

There is no error on netbeans. However button does not work. I am adding
import Oracle.jdbc.pool.OracleDataSource;

this import but this time I am taking "package oracle.jdbc.pool does not exist" error.

Please please please. That is my graduation project. If you cannot solve please announce it.

Posted 1-Aug-12 3:55am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Have you registered the driver?
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Try Following these steps (Check if you missed anything):
1) Import the following packages in your java file:***********
import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;

2) Load and Register the JDBC driver:***********
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

or you can use

3) Connect to database:***********
a) If you are using oracle oci driver,you have to use:
Connection conn = DriverManager.getConnection("", "root", "root");

where is the TNSNAMES entry and root is the username and password.
b) If you are using oracle thin driver,you have to use:
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:3306:mydatabase","root", "root");

where localhost is the host,3306 is the port, mydatabase is the database and root is the username and password.
4) Querying the database:**********
a)create statement:
Statement st = conn.createStatement();

b)write query and execute the query:
ResultSet rs = st.executeQuery("SELECT * from student");

5) Close the statement,resultset and connection:**********
TuranEmre 2-Aug-12 6:56am
Aditaya thanks for your helps. But I am taking another error which is:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no ocijdbc9 in java.library.path
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Aditaya I don't know how to thank you. That was the best. Thank you thank you so much.
I have some problems again. How could I understan my driver is oci or thin ? I tried both but I am taking "java.sql.SQLException: Io exception: The Network Adapter could not establish the connection" error.

try {
         DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
         Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:3306:O10G","plsql_staj", "plsql_staj1");
         Statement st = conn.createStatement();
         ResultSet rs = st.executeQuery("SELECT * from E_USER");
     } catch (SQLException ex) {
         Logger.getLogger(AddNewUser.class.getName()).log(Level.SEVERE, null, ex);

When I used the other option which is
Connection conn = DriverManager.getConnection("", "plsql_staj", "plsql_staj1");

I am taking another error which is:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no ocijdbc9 in java.library.path
Here is my PLSQL connection screen.[^]
Aditya Mangipudi 2-Aug-12 8:31am
Are you running an Oracle database instance on my computer?

Can you connect to the database outside of JDBC via a general client such as Toad?
TuranEmre 2-Aug-12 8:45am
I did not understand sorry Aditya. Plesa help me.
Aditya Mangipudi 3-Aug-12 9:23am
Since you are using a localhost connection to the database (jdbc:oracle:thin:@localhost:3306:O10G"), do you the database on your machine? If yes, try connecting to it using a Oracle Database instance like toad. Google on how to connect to oracle database using toad.
If you are not able to connect to database using the tool, you either did not create any database on your machine or something is blocking your connection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 2 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100