Results 1 to 7 of 7
  1. #1
    xxAlemanxx is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Question Help with Resultset

    Hi, I'm having a little bit of trouble with a resultset, and i want to get an expert opinion or guidance from you guys (the experts) my code connects to Sybase, and I'm able to get a result set from it, i print it out using System.out.println()
    so i know its there and I'm able to see it, problem is i need to re-use, use it (getting the info from Sybase into Oracle) I've been told about Hibernate but my superiors DO NOT want to use it) they want to use a straight line by line approach which it would take a lot of time in my opinion to process 10,000 ++ records, thats the way they want to do it, so no matter what i say would change their minds, here is the tricky part, the part i'm stuck on,
    im able to get my ResultSet, but what then?? what else can i do? is there a way that i can dump my resultset on to a table or how can i reuse what i'm getting back from it, so i can go pop it into Oracle...

    one suggestion i did throw into the mix, use the resultset and make it go into a file, and just use oracle sql*loader to upload the data in bulks, they didn't accept that.
    can someone explain to me how can i make this in JAVA, write up a simple code example or just guide me on what i can do? i'm somewhat experienced in JAVA but i don't know what else to do... I'm pulling my hair out...

    thanx
    Aleman

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Open a second connection to Oracle, obviously, then as you scroll through the resultset using next(), plug those values into a PreparedStatement that you have prepared on the other connection and addBatch() it, then, every 500-1000 rows, call executeBatch().

  3. #3
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    You can't process 10 thousand records one at a time. It will take 30 milliseconds per database clank on a good day. if it takes 100 milliseconds, its gonna take 1000 seconds or 16 minutes to process the 10K records.

    The above idea may work. Or you can do a stored procedure and process many records at a time.

    Oracle has good support for cursors within a selection set

    Just be warned, the syntax and usage of stored procedures is not portable between SyBase/MS SqlServer and Oracle. But sounds like your PHB is ready to pay that price already.

  4. #4
    xxAlemanxx is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Default

    just so people know... i'm not making a storm in a glass... if you come to a forum is to get the knowledge from others and heck if i knew how to do it i would just tell you what you need not just blur out comments like this...

    "Lazy multi-cross-posting idjit. I've answered this question for you twice (without code), but rather than ask questions about the implementation of it, and doing some (God forbid) work for your self, you come back again, whining and begging for others to do it for you. Even if someone does, once it is all said and done, what will you have gained? You still wouldn't undersstand it and at the first sign of trouble would simply come back and whine and beg again for someone to fix it for you.

    God but I'm getting tired of this "just shut up and do it for me" attitude (even if it was expressed somewhat diplomatically this time, it's still the same attitude). "

    masijade or whatever, people come to forums to learn, there is no substitution for a good book, but people come to forums to not just learn but also pass or do knowledge transfer, people who are experienced like to teach, and are not arrogant like you expressing attitudes that i may or may not have, i posted in all forums my doubts as i needed a fast answer, and i do thank you for your response in another Forum but there is no reason start your experiences if you are frustrated then just don't plug in your computer, if you don't want to help than just don't say anything people who want to make it like Ronillo he helped me because maybe this interested him and like to go down and program it... he didn't make it for me he explained it and passed down his knowledge of writing code... and he expressly stated this is not right!! you didn't see him cry about other people not knowing to code... if you are experienced which i think you are and just don't want to help people just stay out of forums why do you come here??? to laugh at people that know how to code??? this is not the intent of a forum... not just mouth of or whine of others... and just to shut your mouth up... i made it.... i finished my code... as i don't care much for you or your comments here is the code that you or others that think that doing code for others is not are responsibility and i as i told Flounder i will make it... just help me create the first one...

    Thanx for expressing your true sentiments of forums you arrogant buffoon, i would like to see you when you post a message stating that you don't know something...

    package Connecting;

    import java.sql.DriverManager;
    import java.sql.Statement;
    import java.sql.ResultSet;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import java.sql.Connection;
    import java.io.*;
    import java.sql.CallableStatement;
    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 o_Connection = null;
    Statement o_Statement = null;
    ResultSet o_ResultSet = null;

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

    String o_Driver = "oracle.jdbc.driver.OracleDriver";
    String o_Url = "jdbc:oracle:thin:@198.162.1.103:1521/Test";
    String s_Driver = "com.sybase.jdbc3.jdbc.SybDataSource";
    String s_Url = "jdbc:sybase:Tds:198.162.1.103:5000/Test_MF";
    //198.162.1.103
    public SybaseConnector() {

    //Load driver
    try {
    Class.forName(o_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 inserting ="";

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

    //Create Statement String objects
    query = "SELECT * FROM Employee";
    inserting = "Insert INTO EmpTest Values (?,?,?,?,?)";

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

    //PreparedStatement ps_Statement;
    PreparedStatement ps_Statement = o_Connection.prepareStatement(inserting);

    //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");

    for(int i = 1;i < 6;i++) {
    ps_Statement.setString(i, s_ResultSet.getString(i));
    }

    ps_Statement.executeUpdate();
    ps_Statement.clearParameters();
    //o_Statement.executeQuery(inserting + s_ResultSet.getString(1) + ", " + s_ResultSet.getString(2) + ", " + s_ResultSet.getString(3) + ", " + s_ResultSet.getString(4) + ", " + s_ResultSet.getString(5) + ")");
    System.out.println("Values Inserted Correctly");
    }

    } catch (SQLException ex) {
    ex.printStackTrace();
    System.out.println(ex);
    } finally {

    try {
    if (o_ResultSet != null)
    o_ResultSet.close();
    if (s_ResultSet != null)
    s_ResultSet.close();
    if (o_Statement != null)
    o_Statement.close();
    if (s_Statement != null)
    s_Statement.close();
    if (o_Connection != null)
    o_Connection.close();
    if (s_Connection != null)
    s_Connection.close();
    } catch (SQLException ex) {
    ex.printStackTrace();
    System.out.println(ex);
    }
    }
    }

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

  5. #5
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by xxAlemanxx View Post
    you what you need not just blur out comments like this...
    [rest of long and not very meaningful repost elided]
    I see nothing in this thread to justify your rant.
    What's the problem here?

  6. #6
    xxAlemanxx is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Default

    well just as masijade expressed his emotions on whether or not to help people i expressed mine against him/her trying to post this exact thing on other forums, as i did posted this exact message on another forum, but asked if i could be help by others helping me write the code, i guess he/she is tired of writing code for people... and as i expressed myself this was to show him that i did in fact did the work that he/she didn't what to help on and this would be just as shout out that people promising to work for instance (me) just needed the help of experienced people to get me going, that's all i needed, you may say hey good for you you did it, or you may say hey you did it what are you whining about now shut up and go about your business, but i wanted to show him that he was mistaken and that helping other people even when you inside of you this guy isn't going to do the code... I'm going to do it for him and what do i have to show for it... nothing... just free advice... i ain't in the business of free business masijade there are other forums that charge for consulting and gosh darnet to do code...

    people come to forums so that they can see what others are doing... or say hey i did it this way or hey i did it this way... but ooohh no masijade just happens to think that helping others doesn't matter and/or just blur out a solution and not realizing that the other person in this case (me) would not have enough experience to start doing it... so i only asked can someone help me do it is that so bad? is that so wrong?? I've seen hundreds of threads saying: hey i got this code can you help me write out this other part of my code people gladly help... and i expressed to the other user in the other forum.. i just need you to help me (or do it) i will understand it and heck guess what i did, and rather than that masijade rant about he being tired of people to asking other people or in his case him/her to code he/she just explodes on me...

    this post is more like a shut you up note... i guess he/she had a bad day but there isn't an excuse for not helping others, if you want to just say hey do it like this... fine... but no discourage others from posting or helping others that's my problem...

    masijade if i offended you in some way i apologize i just want to express that if you want to help people do it without whining or hey here is a thought just don't reply if you don't feel like helping just close the window... simple as that... other users i'm sorry that this is a waste of good thread

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    When you say "give me the code", you are not "coming here to learn", you are coming here to get people to do your work for you.

    You might be in a bit of a jam, and you might even truthfully intend to study the code and figure out exactly what it does, but in 99.99999% of the cases (even when you do mean to study it) you won't. So, giving you the code will not help "you to learn". It will do exactly the opposite.

    And, when you post the same question in several forums, and then, do not bother to respond to posts that do not contain ready to use code, but rather beg more and more openly in each of the subsequent forums for ready to use code, that proves, all the more, that you have no interest in learning, but rather just want a quick cop-out. And this rant, after having been called on it, only proves that all the more.

Similar Threads

  1. MySql ResultSet
    By sandeeprao.techno in forum Advanced Java
    Replies: 7
    Last Post: 06-19-2008, 08:41 AM
  2. ResultSet to XML
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-14-2008, 10:50 AM
  3. ResultSet to JTable
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-11-2008, 10:01 AM
  4. Empty ResultSet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-09-2008, 09:36 PM
  5. ResultSet example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-20-2008, 09:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •