473,804 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Extract File From Oracle 10g Database Using Java

2 New Member
Hello, I am trying to extract the data from my Oracle 10g database using Java.

First, I tried to connect Oracle to Java using this code and it works.

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import java.sql.*;
  3. import java.io.*;
  4. public class TestDBOracle {
  5.  
  6.   public static void main(String[] args) throws ClassNotFoundException, SQLException
  7.   {
  8.     Class.forName("oracle.jdbc.OracleDriver");
  9.  
  10.     String url = "jdbc:oracle:thin:@MY-PC:1521:XE";
  11.  
  12.     Connection conn = DriverManager.getConnection(url,"user", "pwd");
  13.  
  14.     conn.setAutoCommit(false);
  15.     Statement stmt = conn.createStatement();
  16.  
  17.     ResultSet rset = stmt.executeQuery("select NC_ID from NC_TEST");
  18.  
  19.     while (rset.next()) {
  20.          System.out.println (rset.getString(1));  
  21.     }
  22.     stmt.close();
  23.     System.out.println ("Ok.");  
  24.   }
  25. }
  26.  
Next, what I intend to do is to generate a text file from ORACLE. However I get this error.

Exception in thread "main" java.sql.SQLExc eption: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.dri ver.DatabaseErr or.throwSqlExce ption(DatabaseE rror.java:112)
at oracle.jdbc.dri ver.DatabaseErr or.throwSqlExce ption(DatabaseE rror.java:146)
at oracle.jdbc.dri ver.DatabaseErr or.throwSqlExce ption(DatabaseE rror.java:255)
at oracle.jdbc.dri ver.T4CConnecti on.logon(T4CCon nection.java:38 7)
at oracle.jdbc.dri ver.PhysicalCon nection.<init>( PhysicalConnect ion.java:414)
at oracle.jdbc.dri ver.T4CConnecti on.<init>(T4CCo nnection.java:1 65)
at oracle.jdbc.dri ver.T4CDriverEx tension.getConn ection(T4CDrive rExtension.java :35)
at oracle.jdbc.dri ver.OracleDrive r.connect(Oracl eDriver.java:80 1)
at java.sql.Driver Manager.getConn ection(DriverMa nager.java:582)
at java.sql.Driver Manager.getConn ection(DriverMa nager.java:185)
at ExtIndex.main(E xtIndex.java:26 )

I used this code.

Expand|Select|Wrap|Line Numbers
  1. import java.sql.*;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class ExtIndex {
  6.  
  7. public static void main(String[] args) throws ClassNotFoundException, SQLException, IOException
  8. {
  9.  
  10. Class.forName("oracle.jdbc.OracleDriver");
  11. String url = "jdbc:oracle:thin:@MY-PC:1512:XE";
  12.  
  13. Connection conn = DriverManager.getConnection(url,"user","pwd");
  14. conn.setAutoCommit(false);
  15.  
  16.  
  17.  
  18. //------------------------------------------------------------------------//
  19. Statement stmt = conn.createStatement();
  20. ResultSet rset = stmt.executeQuery("select NC_ID from NC_TEST");
  21.  
  22. File file = new File("indexList.txt");
  23. FileWriter outputFile = new FileWriter("indexList.txt");
  24. BufferedWriter fos = new BufferedWriter(outputFile);
  25. String writeOut;
  26.  
  27. try{
  28. while (rset.next()) {
  29. System.out.println (rset.getString(1));
  30. writeOut = rset.getString(1) + "\n";
  31. fos.write(writeOut);
  32. }
  33. }
  34. catch (FileNotFoundException e) {
  35.         System.err.println("FileStreamsTest: " + e);
  36.     } 
  37. catch (IOException e) {
  38.         System.err.println("FileStreamsTest: " + e);
  39.     }finally {
  40.  
  41.             try {
  42.                 if (fos != null) {
  43.                     fos.flush();
  44.                     fos.close();
  45.                 }
  46.             } catch (IOException e) {
  47.                 e.printStackTrace();
  48.             }
  49.         }
  50.  
  51.  
  52.  
  53. stmt.close();
  54. System.out.println ("Index list generation successful");
  55.  
  56. ExtFile.ExtFile();
  57. //--------------------------------------------------------------------------//
  58. }
  59.  
  60. }
  61.  
Thanks for any response.
Mar 29 '11 #1
1 3932
sanat
5 New Member
Exception in thread "main" java.sql.SQLExc eption: Io exception: The Network Adapter could not establish the connection.

I think there is a connection leak in your code.

Also I did not get any code which is closing the connection.
Apr 14 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1098
by: otto | last post by:
Hi, all: We have a Windows application that make operations against an Oracle database. The business logic components are in the server and are accesible from the client interface trought a WebService. The business logic components call the data access layer components and obtain the results. tha problem is as follows: one application requirement is that when a user make some operations, the tables (or rows) he is working to remain locked...
0
2545
by: Asvineo | last post by:
Hi Can anyone please tell me how to connect an Oracle database to a dll written in VC++.Please also mention how to create Connection object,recordset for the same.The dll is an MFC based dll.Please help ASAP Thanks in Advance
2
1877
by: Steve Kershaw | last post by:
I have a need to extract data from an Oracle database using an SQL query. The problem is that I need to insert a parameter into the query. For example: SELECT EMPLOYEE, DED_CODE FROM QUARTDED WHERE STATE = @STATE The problem is that the "@STATE" Dosen't work. When I try to execute the query in Query Builder I get a Invalid column error. Further the query changes from WHERE STATE = @STATE to WHERE STATE =
2
4108
by: Hatricks | last post by:
Hi, How can I store & retrieve PDF file in SQL 2005 database using java. Any code will be of great help.
1
2911
by: Master Ken | last post by:
Hi All, I'm very new to C# and ASP and I am asking for some help as I don't really know where to start on this project. Some background info first I run a report each week which outputs data to an excel spreadsheet, I then have to manually do insert and update query's to our oracle database using this spreadsheet. I would like to create an application that would read the data form the spreadsheet and automatically update the database.
2
6226
by: mannavavp | last post by:
hi friends, please let me know how i can store audio files in database table using java programming?
3
6447
by: techquest | last post by:
Hi, I want to connect into oracle database and export the table data into a flat file using UNIX shell scripts. I cant use other GUI tools to do this, as the dataload will be in millions. hence if i try to export from toad/sqlplus its hanging. And also i need to some validation using UNIX. So please give me some tip to write a script which does this operation. Req: 1) Connect oracle 2) Select * from employee 3) Write into some flat...
5
7352
by: sumanta123 | last post by:
Dear Sir, How to export/import the excel file in oracle database using sql promt. Please guide me the command(export/import) for the neddful. Thanks in Adavance. Regards Sumanta Panda
0
2742
by: akshalika | last post by:
I am new to Biztalk. In my project we need to connect oracle database and insert data into oracle table using BizTalk project. I use WCF Adapter pack(SP2). I create biztalk project then using Consume Adapter Service Add-in create schemas to insert data into oracle database and tow-way send port binding file Then create orchestration and logical receive port send port, Request-response port then after correctly connect those port with message...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.