Results 1 to 2 of 2
Thread: Java + Sybase + Oracle
- 06-18-2008, 03:24 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 4
- Rep Power
- 0
Java + Sybase + Oracle
Hi, I'm developing a project where i need to copy whatever Sybase has in its Database, directly into Oracle... the restriction is that i have to do this via a JAVA program, i have the Oracle and the Sybase classes and are as follows;
my code compiles, and it gives you back a Resultset for whatever column you want, and here comes the tricky part, which is the part I'm stuck on, how can i manipulate a Resultset in a way that i can export that information into an oracle database, do i need to create a repository table? or what else can i do?? because i can get it to display it but i need it to go into to Oracle... any suggestion would be nice, can anyone help??? thanx in adavanced for your help.
xxAlemanxx
package sybaseoracle;
import java.io.*;
import java.sql.*;
import com.sybase.jdbcx.*;
import com.sybase.jdbc3.tds.*;
import com.sybase.jdbc3.jdbc.*;
import com.sybase.jdbc3.timedio.*;
import com.sybase.jdbc3.utils.*;
import java.util.*;
import java.sql.ResultSet;
public class SybaseMainClassRS {
private static final String Make = "create table Test ( " + " id INT PRIMARY KEY, firstName VARCHAR(20), lastName VARCHAR(20), " + " title VARCHAR(20), salary VARCHAR(20) " + ")";
public static Connection getConnection() throws ClassNotFoundException, SQLException {
String driver = "com.sybase.jdbc3.jdbc.SybDataSource";
String url = "jdbc:sybase:Tds:W2VZ2DTT02:5000/testsybase";
String username = "sa";
String password = "";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
public static void main(String args[]) {
Connection conn = null;
Statement stmt = null;
try {
conn = getConnection();
stmt = conn.createStatement();
stmt.executeUpdate(Make);
stmt.executeUpdate("insert into Test(id, firstName, lastName, title, salary) values(100, 'German', 'Garcia', 'Analyst', '3000')");
stmt.executeUpdate("insert into Test(id, firstName, lastName, title, salary) values(200, 'German', 'Grajeola', 'Architect', '5000')");
System.out.println("Table Created.");
} catch (ClassNotFoundException e) {
System.out.println("error: failed to load Sybase driver.");
e.printStackTrace();
} catch (SQLException e) {
System.out.println("error: failed to create a connection object.");
e.printStackTrace();
} catch (Exception e) {
System.out.println("other error:");
e.printStackTrace();
}
try {
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT id FROM Test WHERE id = 200");
while (rs.next()) {
System.out.println(rs.getInt(1));
}
} catch (SQLException e) {
System.out.println("Missing Query Statement");
e.printStackTrace();
} finally {
try {
stmt.close();
conn.close();
} catch (Exception e) {
System.out.println("Can't close the connection");
e.printStackTrace();
}
}
}
}
- 06-26-2008, 07:41 AM #2
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
i dont know sybase but if the data from sybase are currently loaded in the RS i can help with that.
First thing you should do is build the same table in oracle. you must have the same table properties.
here is the command:
rs contains the data from sybase and pstmt shall contain the batch process to be save to oracle
I hope that helpsJava Code:Connection con = null; PreparedStatement pstmt = null; try{Class.forName("oracle.jdbc.OracleDriver"); con = DriverManager.getConnection(jdbc:oracle:thin:@<IP>:<PORT>:<sid>, <Username>, <password>); while(rs.next()) {int l=0; try{ pstmt = con.prepareStatement("INSERT INTO YourTable (id,firstname,lastname) VALUES (" rs.getInt("id") + ",'" + rs.getString("firstname") + "','" + rs.getString("lastname") + "')"); pstmt.addBatch(); if (l % 300 == 0) {l++; pstmt.executeBatch(); con.close(); con = DriverManager.getConnection(jdbc:oracle:thin:@<IP>:<PORT>:<sid>, <Username>, <password>); } }catch(Exception B){} } if ( l % 300 != 0 ){ pstmt.executeBatch(); con.close();} }catch(Exception e){}Last edited by Eku; 06-26-2008 at 07:47 AM.
Mind only knows what lies near the heart, it alone sees the depth of the soul.
Similar Threads
-
How to integrate java application from oracle JDeveloper in MOSS without using Tomcat
By shabana.saginala in forum Advanced JavaReplies: 0Last Post: 06-11-2008, 04:31 PM -
How can I call java class methods in Oracle 10g PL/SQL
By searcher34 in forum JDBCReplies: 0Last Post: 01-02-2008, 01:52 PM -
Error While connecting to Oracle thru JAVA
By javaneed in forum Advanced JavaReplies: 1Last Post: 08-11-2007, 10:05 PM -
S.O.S SyBase Connection
By Marty in forum JDBCReplies: 2Last Post: 05-14-2007, 04:06 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks