Example : A Connectivity Code between Net Beans 8.2 IDE & Oracle 10g/11g (First Step) [NetBeans – Oracle Connectivity Code].
Step 1 - First, Download 'ojdbc7' jar driver file free and store at specific location using Google.
Step 2 - Add 'ojdbc7' jar file into 'Libraries' option of 'Project' tab.(Open Net Beans 8.2 IDE -
Open/create 'Java Application' - Open 'Project' tab of(left top side) Netbeans - Open
'Databases' options - Open 'Drivers' option - Right click on 'Oracle Thin' option - Click
'Connection String' option - Click on 'Add'button - Browse 'ojdbc7' jar file & Open it -
Next button - Put 'SID name' (XE for oracle express edition or) - 'orcl' for Oracle
Enterprise edition, Oracle 'user name' and 'password' in respective box and rest box remain
as it was - check 'Remember Password' box - Click on 'Test Connection' - If error found
check all the boxes and if 'Connection Succeeded'message appear then click on 'Next' button
- click on 'Next' button - click on 'Finish' button - New connection list is appeared in the
'Drivers' list - Open it and use Oracle as GUI.
Example : A Complete Java & Oracle 10g/11g Connectivity Code using Net Beans 8.2 IDE (Second Step) [Java Connectivity Code].
Step 1 - Download 'ojdbc7' jar driver file free and store at specific location using Google.
Step 2 - Add 'ojdbc7' jar file into 'Libraries' option of 'Project' tab.(Open Net Beans 8.2 IDE -
Open created/create new 'Java Application' - Open 'Project' tab of(left top side) Netbeans -
Right click on 'Libraries' - Click 'Add Jar/Folder' option - Select 'ojdbc7' jar file - Open
- 'ojdbc7' jar file added into 'Libraries'.)
Step 3 -
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
//import java.sql.*;
public class UserRegistration extends javax.swing.JFrame
{
static Connection conn = null;
PreparedStatement pst = null;
Statement st = null;
ResultSet rs;
-----
-----
-----
public static void main(String args[])
{
try
{
Netbeans automatically created multiline java codes
---------
---------
}
catch (ClassNotFoundException ex)
{
Netbeans automatically created multiline java codes
---------
---------
}
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl",
"OracleUserName","OraclePassword");
if(conn!=null)
{
System.out.println("Database Connected...!");
}
else
{
System.out.println("Database Connection Error ...!");
}
}
catch(Exception ex)
{
System.out.println(ex);
//showMessageDialog(null,ex,"Error Message",ERROR);
}
/* (Automatically created java Code )Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new registration().setVisible(true);
}
});
}
}
0 Comments