PART 1
Oracle Download
Install Oracle database and do steps below in image
Enter and Run your query here .
Table is created .
PART 2
In windows xp Start --> Control Panel --> Performance and Maintanenace --> Administratvie Tool --> Data Source(odbc)
- ODBC Data Source Administrator dialog box appear
- click Add Button
- Create New Data Source dialog box appear
PART 3
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar
Java Coding
import java.sql.DriverManager;
import java.sql.Statement;
public class InsertRecord {
public static void main(String[] args) {
String driver="sun.jdbc.odbc.JdbcOdbcDriver";
String cs="jdbc:odbc:connectoracle";
String user = "system";
String pwd = "admin";
String sqlstmt="INSERT INTO GANESH2 VALUES(7,'ambross')";
//String sqlstmt1="create table login(ID Number NOT NULL ,Name Varchar2(50),Password Varchar2(50),CONSTRAINT login_PK PRIMARY KEY (ID) ENABLE);";
Connection con = null;
Statement st = null;
try
{
Class.forName(driver);
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println("Driver loaded");
try
{
con=DriverManager.getConnection(cs,user,pwd);
System.out.println("Connected to the Oracle Database");
st = con.createStatement();//creates a Statement object for sending SQL statements to the database.
//st.executeQuery(sqlstmt);
int updatecount=st.executeUpdate(sqlstmt);//return either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
//System.out.println(updatecount+" row inserted");
}
catch(Exception e)
{
System.out.println(e);
}
try
{
st.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}//main()
}//class()
VIEW CODING:
import java.sql.*;
public class oracle {
public static void main(String[] args) {
String driver="sun.jdbc.odbc.JdbcOdbcDriver"; //
String cs="jdbc:odbc:connectOracle"; //connectOracle is the data source name
String user = "system"; //username of oracle database
String pwd = "admin"; //password of oracle database
Connection con = null; //connection variable assigned to null
try
{
Class.forName(driver);// for loading the jdbc driver
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println("JDBC Driver loaded");
try
{
con=DriverManager.getConnection(cs,user,pwd);// for establishing connection with database
Statement s=con.createStatement();
ResultSet r=s.executeQuery("select * from ganesh2");
while(r.next())
{
System.out.println("ID:"+r.getInt("id")+" Password:"+r.getString("name"));
}
}
catch(Exception e)
{
System.out.println(e);
}
System.out.println("Connected to the Oracle Database");
try
{
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}//end of main()
}//end of class()