Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-18-2008, 04:24 PM
Member
 
Join Date: Jun 2008
Posts: 4
xxAlemanxx is on a distinguished road
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();
}
}
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-26-2008, 08:41 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 188
Eku is on a distinguished road
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

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){}
I hope that helps
__________________
Mind only knows what lies near the heart, it alone sees the depth of the soul.

Last edited by Eku : 06-26-2008 at 08:47 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to integrate java application from oracle JDeveloper in MOSS without using Tomcat shabana.saginala Advanced Java 0 06-11-2008 05:31 PM
How can I call java class methods in Oracle 10g PL/SQL searcher34 Database 0 01-02-2008 02:52 PM
Error While connecting to Oracle thru JAVA javaneed Advanced Java 1 08-11-2007 11:05 PM
S.O.S SyBase Connection Marty Database 2 05-14-2007 05:06 PM
Migration from oracle forms to java Nick15 Advanced Java 3 05-12-2007 08:00 AM


All times are GMT +3. The time now is 01:12 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org