• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

need java logic

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody...,


I am trying to retreive data from sql db tables, and insert into oracale db table.before inserting into oracle table i have to check the modified date column in oracle. if sql table is having updated data i have to insert.

I am using jdbc api. I got connected to both databases and retreived data from databases. the code i wrote is below, but am stucked at comparing the data and inserting into oracle.
please help me.......

Thanks in advanse
---------------------------------------------------------------------------

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class Conn {

Connection con = null;

public static Connection getSqlConnection(String Username, String Password)
throws SQLException {
String url = "jdbc:sqlserver://localhost\\SQLEXPRESSS:1433;databaseName=Murthy;";
Connection con = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(url, Username, Password);
if (con != null)
System.out.println("connected");
else
System.out.println("not connected");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}

public static Connection getOracleConnection(String Username,
String Password) throws SQLException {
String url = "jdbc:oracle:thin:@localhost:1521:XE";
Connection con = null;

try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, Username, Password);
if (con != null)
System.out.println("connected");
else
System.out.println("not connected");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return con;
}

public void read() throws SQLException {
Connection con = null;
ResultSet res = null;
Statement stmt = null;
try {
con = getSqlConnection("sa", "amsol");
stmt = con.createStatement();
String query = "select * from [User]";
res = stmt.executeQuery(query);
while (res.next()) {

String ans = res.getString(1);
String ans1 = res.getString(2);
String ans2 = res.getString(3);
String ans3 = res.getString(4);
String ans4 = res.getString(5);
}

} catch (Exception e) {
System.out.println(e);
}

finally {
try {
if (stmt != null) stmt.close();
}
catch (Exception ee) {
} try { if (con != null) con.close(); } catch (Exception c) { } }


}

public void read2() throws SQLException {
con = getOracleConnection("system", "murthy");
Statement stmt = con.createStatement();
String query = "select * from tb_User";
ResultSet res1 = stmt.executeQuery(query);
while (res1.next()) {

String data = res1.getString(8);

}
}

public static void main(String[] args) throws SQLException {
Conn connect = new Conn();
connect.read();
connect.read2();


}

}
 
author
Posts: 4173
29
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be more specific in what you're stuck at. It sounds like since you're able to read all the data, that this might not even be a JDBC issue. Comparing objects is more of a java issue than anything else, but I'll leave this in the JDBC forum for now. Please clarify exactly what the problem is.
 
Murthy Manchala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Scott,

I am unable to compare the two resultset objects. I have to compare them based on that i have to either update the row in oracle db or insert the row into oracle db.

I am trying to compare the objects in main method.

I tried arraylist,<pojo> they are not working. can you give me idea how to compare the objects. if i use the resultset object it is saying like resultset is not having any row it is closed.

Thanks..
 
Scott Selikoff
author
Posts: 4173
29
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by comparing objects?

Resultsets is really just a fancy list of HashMaps, read one HashMap at a time.

If you can read the data, this really isn't a JDBC issue so I'm going to move this Java Intermediate and hopefully someone can help you 'compare objects' as you want to do.
[ August 21, 2008: Message edited by: Scott Selikoff ]
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic