/* HERE IS MY CODE */
import java.sql.*;
import java.io.*;
public class oracle_mysql_demo
{
public static void main(
String args[])
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con1 = DriverManager.getConnection ("jdbc

racle:thin:@64.240.98.211:1521:cricket","boli","boli");
Statement st1=con1.createStatement();
Statement st3=con1.createStatement();
Statement st5=con1.createStatement();
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection con2 = DriverManager.getConnection("jdbc:mysql://localhost/Team");
Statement st2 = con2.createStatement();
Statement st4 = con2.createStatement();
Statement st6 = con2.createStatement();
ResultSet r1 = st1.executeQuery("Select * from uma_example");
ResultSet r2 = st2.executeQuery("Select * from uma_demo");
ResultSet r3 = st3.executeQuery("SELECT COUNT(*) FROM uma_example");
r3.next();
int rowcount1 = r3.getInt("COUNT(*)");
System.out.println("\nThe number of rows in table uma_example are :"+rowcount1);
ResultSet r4 = st4.executeQuery("SELECT COUNT(*) FROM uma_demo");
r4.next();
int rowcount2 = r4.getInt("COUNT(*)");
System.out.println("\nThe number of rows in table uma_demo are :"+rowcount2);
while(r1.next())
{
r2.next();
if(r1.getInt("id_no")==r2.getInt("id_no"))
{
int j=st2.executeUpdate("UPDATE uma_demo SET name ='"+r1.getString("name")+"',salary ="+r1.getInt("salary")+" WHERE id_no="+r1.getInt("id_no")+"");
System.out.println("The row which has been checked or updated is:"+r1.getInt("id_no"));
}
else
{
if(r1.getInt("id_no") != r2.getInt("id_no") | | rowcount2==0)
{
int i=st2.executeUpdate("INSERT INTO uma_demo VALUES("+r1.getInt("id_no")+",'"+r1.getString("name")+"',"+r1.getInt("salary")+")");
System.out.println("The record inserted was : "+r1.getInt("id_no"));
}
}
/*if((rowcount1<rowcount2))>
{
int k=st2.executeUpdate("DELETE FROM uma_demo WHERE id_no != "+r1.getInt("id_no")+"");
System.out.println("The deleted rows were :"+r1.getInt("id_no"));
}*/
}
}
catch(Exception e)
{
System.out.println("\nThe message is !!"+e);
}
}
}
/**************************************************************/
My problem is if the table in mysql is empty i have to insert all the rows from oracle table. But it is giving me error that "Before start of ResultSet". If atleast one row is existing it is inserting and updating the table. In delete also if we happen to delete a row from oracle table it has to delete in mysql also. these are my doubts. I will be really thankful if you clear my doubts.
thankyou
uma