Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.databases > #552
| From | Sathish@myc2s.com |
|---|---|
| Newsgroups | comp.lang.java.databases |
| Subject | Re: copy data from one database to another |
| Date | 2012-08-12 23:43 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <057be9ae-208a-4601-a5b2-9ed8c64f5d9a@googlegroups.com> (permalink) |
| References | <35bb23f9-03ca-41a3-9bba-0cd5ee0c3162@z20g2000prh.googlegroups.com> |
On Friday, June 12, 2009 5:13:51 PM UTC+5:30, bazzer wrote:
> Hi
>
> I am trying to go about copying data from one database to another. The
> source database is SQL server, and the destination is an Oracle
> database. While I can access both database' fine, and insert into the
> oracle database fine, I am having trouble copying data from the SQL DB
> to the Oracle DB. What I was initially trying to do was copy all the
> required data into a resultSet, and then transfer this into the Oracle
> DB. But i probablt cannot insert this block of data in the resultSet
> directly into the Oracle db i supposed??? If anyone could suggest a
> better more efficient way to transfer the data i would be grateful.
> Please see below a snippet of the code for transferring the data. For
> the moment I am only copying rows between a certain timestamp. Its
> seems to run fine, and I am not getting an error, but when I check the
> Oracle database, there is no data in it.
>
> //setup the drivers
> DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver
> ());
> DriverManager.registerDriver(new
> oracle.jdbc.driver.OracleDriver());
>
> //connect to the MySQL database
> Connection connSQL = DriverManager.getConnection(
> "jdbc:odbc:Owenreagh", "username", "password");
> System.out.println("connected to SQL DB successfully");
>
> //connect to the Oracle database
> Connection connOra = DriverManager.getConnection(
> "jdbc:oracle:thin:@hostname:1521:DBname", // URL
> "username", // username
> "password" // password
> );
> System.out.println("connected to Oracle DB successfully");
>
> Statement mySQLstat = connSQL.createStatement();
> Statement myOrastat = connOra.createStatement();
>
> ResultSet rsSQL = mySQLstat.executeQuery(
> "SELECT * FROM Owenreagh.dbo.T_WTG06_10MINDATA WHERE
> ((T_WTG06_10MINDATA.TTimeStamp>{ts '2009-01-01 00:10:00'}) AND
> (T_WTG06_10MINDATA.TTimeStamp<{ts '2009-01-01 00:10:30'}))");
>
> ResultSetMetaData rsSQLmd = rsSQL.getMetaData();
> int numberOfColumns = rsSQLmd.getColumnCount();
> int max = numberOfColumns + 1;
>
> int index;
> while(rsSQL.next()){
> for(index = 1; index < max; index++) {
> myOrastat.executeQuery("INSERT INTO VESTASTURBINEDATA
> VALUES" +
> rsSQL.getString
> (index));
> }
> }
Back to comp.lang.java.databases | Previous | Next — Next in thread | Find similar
Re: copy data from one database to another Sathish@myc2s.com - 2012-08-12 23:43 -0700 Re: copy data from one database to another Lew <noone@lewscanon.com> - 2012-08-18 11:09 -0700 Re: copy data from one database to another Roedy Green <see_website@mindprod.com.invalid> - 2012-08-24 11:02 -0700
csiph-web