Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. 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 contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Help Needed newbee in Java

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-22-08, 21:57
Yerman Yerman is offline
Registered User
 
Join Date: Mar 2006
Posts: 21
Question Help Needed newbee in Java

hi, i been trying to get my code working, can anyone help me?? i just need to complete the insert from my sybase server to my oracle server, i have setup my sybase tables already which are
id, fName, lName, title, salary
im trying to pass my tables to Oracle, which one would be better ResultSet.getString or ResultSet.getMetaData()... either way im stuck... i'm trying to do it generically
i used system.out.println so tell me if i was getting something i am... im getting column by column... is there a way just get the entire table and just plug it into Oracle
can anyone helpme comple this darn code...

thanx alot for your input i really appreciate it...

import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Connection;
import java.io.*;
import oracle.jdbc.driver.OracleConnection;
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.*;

public class SybaseConnector {

Connection m_Connection = null;
Statement m_Statement = null;
ResultSet m_ResultSet = null;

Connection s_Connection = null;
Statement s_Statement = null;
ResultSet s_ResultSet = null;

String m_Driver = "oracle.jdbc.driver.OracleDriver";
String m_Url = "jdbcracle:thin:@w2vz2dtt02:1521:Test";
String s_Driver = "com.sybase.jdbc3.jdbc.SybDataSource";
String s_Url = "jdbc:sybase:Tds:192.168.1.103:5000/testsybase";
//198.162.1.103
public SybaseConnector() {

//Load driver
try {
Class.forName(m_Driver);
Class.forName(s_Driver);
System.out.println("Driver for Oracle loaded Successfully");
System.out.println("Driver for Sybase loaded Successfully");
}
catch (ClassNotFoundException ex) {
System.out.println("Oracle Driver was not loaded successfully");
System.out.println("Sybase Driver was not loaded successfully");
ex.printStackTrace();
}
}

public void doWork() {

String query = "";
//String execute = "";
//String create = "";
try {
//Create connection object
m_Connection = DriverManager.getConnection(m_Url, "system", "e9876");
System.out.println("Connected to Oracle Successfully");
s_Connection = DriverManager.getConnection(s_Url, "sa", "");
System.out.println("Connected to Sybase Successfully");

//Create Statement object
s_Statement = s_Connection.createStatement();
query = "SELECT * FROM employee";


//Execute the query
s_ResultSet = s_Statement.executeQuery(query);

//Loop through the results
while (s_ResultSet.next()) {
System.out.print(s_ResultSet.getString(1) + " " + s_ResultSet.getString(2) + " " + s_ResultSet.getString(3) + " " + s_ResultSet.getString(4) + " " + s_ResultSet.getString(5)+"\n");
}
}
catch (SQLException ex) {
ex.printStackTrace();
System.out.println(query);
}
finally {

try {
if (m_ResultSet != null)
m_ResultSet.close();
if (m_Statement != null)
m_Statement.close();
if (m_Connection != null)
m_Connection.close();
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
}

public static void main(String[] args) {
SybaseConnector Test = new SybaseConnector();
Test.doWork();
}
}
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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