Important alert: (current site time 7/15/2013 3:49:56 PM EDT)
 

VB icon

Oracle database connectivity

Email
Submitted on: 3/30/2008 11:11:02 AM
By: Muthukumar Lakshmipathi  
Level: Beginner
User Rating: By 3 Users
Compatibility: Java (JDK 1.5)
Views: 8701
author picture
 
     simple and effective program for connecting oracle with java and methods available for insertion, updation and deletion
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: Oracle database connectivity
// Description:simple and effective program for connecting oracle with java and methods available for insertion, updation and deletion
// By: Muthukumar Lakshmipathi
//
// Inputs:not required
//
// Side Effects:i used JDBC and ODBC bridge so i works in Windows only
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=5957&lngWId=2//for details.//**************************************

/*
 programmer name:Muthukumar and Deva
steps for creating data source
control panel->Administrative Tools->Data Sources (ODBC)->
select user DSN tab then click add button
select Microsoft ODBC driver for Oracle
fill your data source (here it is patni)
and username and servername(oracle)
click of
Limitations:
 This code only works in Windows platform
*/
import java.sql.*;
class Connectivity
{
Connection conn;
 Statement stmt;
 PreparedStatement s1;
 void connect()
 {
try
{
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
 
 conn = DriverManager.getConnection("jdbc:odbc:patni","devarajan","devarajan");
 // patni--->datasource,devarajan---->username,devarajan->password
}
catch(Exception e)
{
 System.out.println("ee"+e.getMessage());
 
}
 } 
 
 void insertData(String nme,String roll)
 {
try
{
 s1=conn.prepareStatement("insert into stu values(?,?)");
s1.setString(1,nme);
s1.setString(2,roll);
s1.executeUpdate();
System.out.println("Record inserted"); 
s1.close();
}
catch(Exception s)
{
 System.out.println(s.getMessage());
}
 
 }
 
void updateData()
 {
try
{
stmt=conn.createStatement();
int i=stmt.executeUpdate("update stu set name='muthukumar4u' where roll='05mx23'" );
System.out.println("\t\t\t"+i +" record updated in updation funtion"); 
stmt.close();
}
catch(Exception s){
 System.out.println(s.getMessage());
}
 
 }
 void deleteData()
 {
try
{
stmt=conn.createStatement(); 
int i=stmt.executeUpdate("delete from stu where name='muthukumar4u'" );
System.out.println(i+" records Deleted"); 
stmt.close();
}
catch(Exception s){
 System.out.println(s.getMessage());
}
 }
 void displayData()
 {
try
{
stmt=conn.createStatement(); 
ResultSet rs = stmt.executeQuery("select * from stu"); 
System.out.println("The table contains:");
while(rs.next())
{
 System.out.println("Name:"+rs.getString("name"));
 System.out.print("Roll no:"+rs.getString("roll")); 
}
}
catch(Exception e)
{
 System.out.println(e.getMessage());
}
 }
}
public class JavatoOracle 
{
 
public static void main(String args[])
{
 Connectivity c=new Connectivity();
c.connect();
c.insertData("muthukumar", "05mx23");
c.displayData();
c.updateData();
c.displayData();
c.deleteData();
c.displayData();
}
}


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

5/5/2009 2:20:12 PMAyush

No, my friend..this is not Oracle Connectivity...this is a simple Jdbc:Odbc connectivity i.e. MS Access.......
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.