Treating a text file as a database

I would like to create a database in the form of a simple text file and use Java to access/maintain it.
I was thinking at first that JDBC-ODBC would be the way to go but I'm having syntax problems.
Is there a better way to handle this? Or perhaps does someone have a good example they could share with me?

If you already know SQL, writing your own JDBC driver that will create and access XML documents is easy
by John B. O'Donahue
As Java programmers, we have probably all used JDBC drivers. But until I received a project that was shipped without the commercial database it was built around, I had never thought of writing my own JDBC driver.
A major factor in my decision to attempt writing my own driver was that I was creating XML documents from my database tables anyway. It made sense to use the XML documents as my storage medium, and either replace the entire interface with a DOM interface, or write a JDBC driver to interface to the XML. Well, I hate ripping out code that works, and writing a JDBC driver looked like a lot of fun, so the decision was easy.
The main limitation of XML parsers is that they address the mechanics of the document, although the user is generally much more interested in content. The JDBC API, on the other hand, is geared toward handling data. A marriage of the two can give you the best of both worlds, particularly when you consider that a huge percentage of the XML on the Web was generated automatically from a database in the first place.
In this article, we'll be using the moreover.com news feeds as a real-world example of a practical use of XML. This example also shows off the advantages of a SQL-based approach. We really just want to scan for stories that interest the user, in much the same way as we scan newspaper headlines. A SQL query for headlines containing specific topics is a much more natural, content-oriented approach than a tree-parsing model, which is essentially document oriented.
http://www.devx.com/premier/mgznarch/Javapro/2001/01dec01/jo0112/jo0112-1.asp

Similar Messages

  • How to store text file in MySql database

    Hello Sir/Madam,
    I want to store and retreive text file in mysql database ,Please give some ideas and send me code examples.

    We keep ideas and examples of this issue here:
    http://www.google.com/search?q=mysql+jdbc+clob

  • Cannot get text file to print in jtable. Using text file as a database

    Instead of doing JDBC i am using text file as database. I cant get data from text file to print into JTable when i click find button. Goal is to find a record and print that record only, but for now i am trying to print all the records. Once i get that i will change my code to search desired record and print it. when i click the find button nothing happens. Can you please take a look at my code, dbTest() method. thanks.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.util.*;
    import java.io.*;
    public class GUIdirectory extends JFrame
    implements ActionListener {
    // Define the components and the layout
    JLabel inputLabel_lastname = new JLabel("Last Name");
    JTextField inputText_lastname = new JTextField("Last Name",15);
    JLabel inputLabel_firstname = new JLabel("First Name");
    JTextField inputText_firstname = new JTextField(" ",15);
    JLabel inputLabel_middleinitial = new JLabel("Middle Initial");
    JTextField inputText_middleinitial = new JTextField(" ",4);
    JButton inputButton = new JButton("Find");
    JPanel inputLayout = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
    JButton jButton1 = new JButton();
    //create a new table and scrollpane
    JTable dataTable = new JTable();
    JScrollPane dataTableScrollPane = new JScrollPane();
    public static void main(String args[]) {
    GUIdirectory gui = new GUIdirectory("Telephone Directory");
    gui.show();
    gui.pack();
    //TokenTest tt = new TokenTest();
    //gui.dbTest();
    public GUIdirectory(String Title) {
    super(Title);
    // Add ourselves as a listener for the window closing
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent we) {
    exitWindow(1); }
    inputLabel_lastname.setLabelFor(inputText_lastname);
    inputText_lastname.setHorizontalAlignment(JTextField.RIGHT);
    inputText_lastname.addActionListener(this);
    inputLabel_firstname.setLabelFor(inputText_firstname);
    inputText_firstname.setHorizontalAlignment(JTextField.RIGHT);
    inputText_firstname.addActionListener(this);
    inputLabel_middleinitial.setLabelFor(inputText_middleinitial);
    inputText_middleinitial.setHorizontalAlignment(JTextField.RIGHT);
    inputText_middleinitial.addActionListener(this);
    inputButton.addActionListener(this);
    inputLayout.add(inputLabel_lastname);
    inputLayout.add(inputText_lastname);
    inputLayout.add(inputLabel_firstname);
    inputLayout.add(inputText_firstname);
    inputLayout.add(inputLabel_middleinitial);
    inputLayout.add(inputText_middleinitial);
    inputLayout.add(inputButton);
    getContentPane().setLayout(new BorderLayout(5,5));
    getContentPane().add("North",inputLayout);
    dataTableScrollPane.setViewportView(dataTable);
    getContentPane().add("Center",dataTableScrollPane);
    // A default method, primarily used for testing.
    public void actionPerformed(ActionEvent evt) {
    GUIdirectory gui = new GUIdirectory();
    gui.dbTest();
    void dbTest() {
    DataInputStream dis = null;
    String dbRecord = null;
    String hold;
    try {
    File f = new File("customer.txt");
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);
    Vector dataVector = new Vector();
    Vector headVector = new Vector(2);
    Vector row = new Vector();
    // read the record of the text database
    while ( (dbRecord = dis.readLine()) != null) {
    StringTokenizer st = new StringTokenizer(dbRecord, ",");
    while (st.hasMoreTokens()) {
    row.addElement(st.nextToken());
    System.out.println("Inside nested loop: " + row);
    System.out.println("inside loop: " + row);
    dataVector.addElement(row);
    System.out.println("outside loop: " + row);
    headVector.addElement("Title");
    headVector.addElement("Type");
    dataTable = new JTable(dataVector, headVector);
    dataTableScrollPane.setViewportView(dataTable);
    } catch (IOException e) {
    // catch io errors from FileInputStream or readLine()
    System.out.println("Uh oh, got an IOException error!" + e.getMessage());
    } finally {
    // if the file opened okay, make sure we close it
    if (dis != null) {
    try {
    dis.close();
    } catch (IOException ioe) {
    } // end if
    } // end finally
    } // end dbTest
    // Exits the program upon closing the window
    public void exitWindow(int i) {
    System.exit(i);
    public GUIdirectory() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    private void jbInit() throws Exception {
    jButton1.setText("jButton1");
    this.getContentPane().add(jButton1, BorderLayout.CENTER);

    Nothing happens because in the actionPerformed() method you are creating a new version of GUIdirectory. You just want to execute the dbTest() method of the current instance of GUIdirectory.
    The code should be:
    public void actionPerformed(ActionEvent evt)
    //GUIdirectory gui = new GUIdirectory();
    //gui.dbTest();
    dbTest();

  • Text file to Access database

    How to add Data from text file in to access database?pls guide

    No, he's claiming that MySQL has an "Import"
    statement (which maybe it does) and wants to know if
    MS Access has the same thing. Apparently he thinks
    this has something to do with Java programming.Interesting. Were I the OP, I would try File -> Open, or File -> Import, or some such command. Also I would try an Access forum rather than a Java one...

  • Text file statement into database

    Dear All,
    I am trying to fetch data from a text file in to Oracle database to print.
    The problem I have is that I cannot gather data because this is a text statement, generated by a report utility and the data consist of multiple dimensions.
    First 3 fields of data are in the first 3 rows of a page and the rest is displayed column wise for the next 20 rows (5th row to 24th Row). Then there is a page break character ASCII (012) (Hex - 0C)then the next record starts.
    Please give me a solution to fetch first 3 lines to one master table & the column of data to a detail table.
    <page breake>
    Code:123456
    Name:1233445566
    Address:aaaaaaaaaaaaa
    Detail1 Detail2 Detail3
    ======= ======= =======
    AAAAAAA BBBBBBB CCCCCCC
    AAAAAAA BBBBBBB CCCCCCC
    <page break>
    Code:123457
    Name:AAAAAAAA
    Address:AAAAAAAA
    Detail1 Detail2 Detail3
    ======= ======= =======
    AAAAAAA BBBBBBB CCCCCCC
    AAAAAAA BBBBBBB CCCCCCC
    Thank you in advance..
    Regards, Lakmal

    Try using the package UTL_FILE.
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_file.htm#998101

  • How to read\write text file into oracle database.

    Hello,
    I am having text file called getInfo in c:\temp folder. I would like to populate data from text file to data base. How to proceed. Could anybody help me out.
    Thanks,
    Shailu

    Here is a web page with easy to follow instructions regarding external files: http://www.adp-gmbh.ch/ora/misc/ext_table.html.
    Now I understand what all the excitement is over external tables.
    "External tables can read flat files (that follow some rules) as though they were ordinary (although read-only) Oracle tables. Therefore, it is convenient to use external tables to load flat files into the DB." -from the above link.

  • Importing text file to Access database

    This is my first time working with Java and databases so I'm very green.
    I need to read a delimited .txt file in (I know how to do this), separate the text by delimiters (I know how), open the connection to database (don't know), write to database table column by column (don't know).
    I appreciate any help.
    Scottie

    Hi Scott,
    I need to do the same thing. Read from a binary file, convert the data and store it in Microsoft Access. What are your suggestions on the best way to do this? Java seems slow with file manipulation. Thanks.
    Regards,
    Mallika

  • Reading text file from database server in OA Page

    Hi Guys,
    I am trying to embed an applet with in an OA Page. The applet is used to mainly for showing Gantt chart. I have to pass my connection details from OA Page to applet, I dont pass directly the connection details to the applet so i am placing all the server details, user name and password in a text file on the database server.
    So from the OA Page i have to read the contents of the file on the database server and pass them to the applet using the <PARAM> tag. My question is how to read the text file from the database server.Any Inputs?
    Thanks in advance for your help.
    Regards,
    Nagesh Manda.

    If the file to be read is on the database, then it makes sense to use the pl/sql code to read the file. Make a call to this pl/sql code from page controller to get back the values.
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                           

  • Read a text file(database) from a servlet for j2me..?

    Anyone know how to read data from a text file as a database using a servlet for j2me..?
    How to do it..?
    Thanks in advance.

    i tried something like that but there is a NullPointerException... Is what i'm doing correct..?
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class LoginServlet extends HttpServlet {
      private static final String db_server = "localhost/";
      private Connection con = null;
      private String content="";
    public void doPost(HttpServletRequest  request,
                         HttpServletResponse response)
        throws ServletException, IOException
        response.setContentType("text/plain");
        PrintWriter out = response.getWriter();
        String strUserid = request.getParameter("userid");
        String strPassword = request.getParameter("password");
        System.out.println("userid received: " + strUserid);
        System.out.println("password received: " + strPassword);
         try{
                   System.out.println("opening the file....");
                   //String url = "file://"+dbServer+"test.txt";
                   //String uri = "file://localhost/test.txt";
                   String uri = "file://Program Files\Apache Group\Tomcat 4.1\webapps\Project\WEB-INF\classes\trial\test.txt";
                   //String uri = "file:/database/res/test.txt";
                   System.out.println( uri );
                   InputConnection conn = (InputConnection) Connector.open( uri,Connector.READ );
                   System.out.println("connection established");
                   InputStream in = conn.openInputStream();
                   int ch;
                   conn.close(); // doesn't close input stream!
                   System.out.println( "Contents of [" + uri +"]" );
                   while( ( ch = in.read() ) != -1 ){
                   System.out.print( (char) ch );
                   in.close();
                   catch( ConnectionNotFoundException e ){
                  System.out.println( e.toString()+"File could not be found!" );
                  System.out.println( "File could not be found!" );
                   catch( IOException e ){
                       System.out.println( e.toString() );
                   catch( Exception e ){
                       System.out.println( e.toString() );
          out.close();
        } // End try
        catch (Exception e) {
          System.out.println("Exception in doPost(): " + e.getMessage() );
      } // End doPost
    } // End loginServlet

  • Text file storing in a database table

    I have a text file, that contains so many lines in it,..
    Now the problem is that.. I want to store my text file with the pl/sql code in a database table....
    plz suggest, how to create a table and how to store that text file in a database table.....

    The following code is tested and get the correct result (forms 10.1.2.0):
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> create table tclob  (col_lob clob);
    Table created.
    Declare
      file  TEXT_IO.FILE_TYPE;
      text  varchar2(10000);
      L$Clob CLOB;
    Begin
      -- prepare CLOB object --
      dbms_lob.createtemporary( L$Clob, TRUE ) ;
      -- open text file --
      file := TEXT_IO.FOPEN( 'c:\forms.css', 'R' ) ;
      If TEXT_IO.IS_OPEN( file) Then
        -- start reazding file --
         Begin
           Loop
             TEXT_IO.GET_LINE( file, text );
             -- add the line to the CLOB variable --
                dbms_lob.writeappend (L$Clob, length(text), text);
           End loop;
        Exception
          when no_data_found then
            -- end of text file --
            TEXT_IO.FCLOSE(file);
          when others then
           null;
        End ;
        -- store the CLOB in the database --
        --Update tclob Set col_lob = L$Clob ;
        insert into tclob (col_lob) values (L$Clob);
        forms_ddl('commit');
           dbms_lob.freetemporary( L$Clob ) ;
      End if ;
    exception
         when others then
         message(error_code || '-' || error_text);
    End;Francois

  • Create text file in Database Trigger

    Hello,
    How to create text file in the database trigger. I am working on Row level trigger which has select statement if statement fails I have to create text file and insert record in text file. I tried to use file1 TEXT_IO.FILE_TYPE package it does not works.
    Thanks,
    Atif

    TEXT_IO is not available on the database. It is only available if you are doing client-side PL/SQL development in Oracle Forms. On the database side, you can use the UTL_FILE package.
    Since writing to a file is not transactional, however, and because Oracle may have to call a trigger multiple times to ensure write consistency:
    http://tkyte.blogspot.com/2005/09/part-iii-why-is-restart-important-to.html
    http://tkyte.blogspot.com/2005/08/part-ii-seeing-restart.html
    http://tkyte.blogspot.com/2005/08/something-different-part-i-of-iii.html
    you aregenerally better off not writing to a file in a trigger. The better answer is generally to use Oracle Asynchronous Queues to send a message to another process that actually writes the file. That way, if the transaction rolls back, nothing gets written to the file.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Producing text file from PL/SQL procedure (UTL_FILE)?

    Hi,
    I need to produce a text file from a PL/SQL procedure. My output should be a little over 38K records and my query has 70 fields. I'd like to separate the fields by pipe delimiters in the text file. I can either concatenate all 70 fields into one variable for each record or send all 70 fields over with a pipe, whichever is easier. It looks like I can't spool within PL/SQL but UTL_FILE might be an option from what I'm reading. Does anyone have any good, simple example(s) to produce a text file using this package in calling multiple fields from a LOOP? Our os is UNIX and db is Oracle 9i.
    Also, I've read that UTL_FILE has a record output of 1,023 bytes. Is this for each record line or the whole file size? I belive the max # of characters for each line wouldn't exceed 500 characters. The 38K rows I have for the data set would be well over 1MB. If this is the case, is there a work around to produce a larger text file?
    Any suggestions and/or examples would be greatly appreciated.
    Thanks,
    Eric

    Assuming the goal is to create a text file on the database server, you can use UTL_FILE here. Each line can be 1023 characters, but you can have as many lines as you'd like.
    Tom Kyte has an example here
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:235814350980
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Search text file with 2 string tokens

    I am reading a text file which contains database records. I am able to search with lastname(the user enters it in the textfield using GUI frontend). this search useus stringtokenizers. take the users input and search all the tokens and see which token matches the key and prints that record. Can someone please give me some advice to do a search using both last name and first name at the same time. In this case i will have to do a seach using 2 tokens which i dont know how to do. thanks.

    Here is the snippet of my code. Can someone please take a look at it.
    while ( (dbRecord = dis.readLine()) != null) {
    StringTokenizer st = new StringTokenizer(dbRecord, ":", false);
    Vector row = new Vector();
    String lineTemp;
    while (st.hasMoreTokens()) {
    if (st.nextToken().trim().equalsIgnoreCase(userinput)) {
    //System.out.println(dbRecord);
    StringTokenizer tempst = new StringTokenizer(dbRecord, ":", false);
    while (tempst.hasMoreTokens()){
    row.addElement(tempst.nextToken());
    dataVector.addElement(row);
    }

  • How do i read a context of text file within Dynamic Page of portal ?

    Dear sir,
    I have a text file in client computer. I hope i can transfer the context words of this text file to oracle database. How do i coding this script in dynamic page of portal?
    Can Oaracle 9ias script read and draw the context of a document. Thank you ver much!
    Ghia Liu

    Great questions, Rik, and I understand how this might seem bizarre. Here's the story... these 2500 files were authored with a built-in authoring tool of our current knowledge management system. This KMS is about to be replaced with a new one and because the new KMS needs content within the <head> tag instead of where it was in the <body> tag and redefined as meta data, I repuposed the content in those files using Dreamweaver and regular expressions.  However, the one remaining <h3> and <p> content is in the middle of the newly tagged meta data and it must be moved from the <head> area and into the <body> area.
    Because these were authored in the built-in KMS authoring tool, there is no style sheet and no, we do not manage our content with a CMS.
    You are correct, if the <h3> and <p> were at the end of the data, I could simply move the </head> and <body> tags, but unfortunately that is not the case.  They are consistenly in the same place in all 2500 files, but in the middle of the data. Following is an example:
    <html>
    <head>
    <title>Title here</title>
    <meta name="XYZ" content="Something here...">
    <h3> Blah blah</h3> <p>More blah blah</p>
    <meta name="123" content="More somthing here">
    <meta name="456" content="More somthing here">
    </head>
    <body>
    </body>
    </html>
    Again, I can find the block using a regular expression <h3>(.*?)</p>, but dont know what to do after that.
    I've been told that perl or grep might do the needed task, but that requires outside resources and I have no budget for that.
    Any suggestions are greatly appreciated.
    thanks,
    Rick

  • Prob in transferring the chinese texts from the text file (UTF-8) into SAP

    Hello SAP Experts ,
    We are using 4.6 C version
    I created a ABAP to upload Chinese Chars from a text file to SAP Database. The coding that I use to read the text file is showed as following:
    CALL FUNCTION 'WS_UPLOAD'
           EXPORTING
                CODEPAGE                = '8400'
                FILENAME                  = P_FILE
                FILETYPE                   = 'DAT'
           TABLES
                DATA_TAB                = LT_FILE_ADD_DATA
           EXCEPTIONS
                CONVERSION_ERROR        = 1
                FILE_OPEN_ERROR         = 2
                FILE_READ_ERROR         = 3
                INVALID_TYPE            = 4
                NO_BATCH                = 5
                UNKNOWN_ERROR           = 6
                INVALID_TABLE_WIDTH     = 7
                GUI_REFUSE_FILETRANSFER = 8
                CUSTOMER_ERROR          = 9
                OTHERS                  = 10.
      IF SY-SUBRC NE 0 .
      ENDIF.
    I use ABAP debugger to check the field values of the internal table .  But, the values of the internal table which contains chinese chars are changed to some other Chinese characters . How to fix this problem?
    I have used ASC filedatatype , but it doesn't work .
    Thanks for your reply . 
    Regards,
    Chopra

    Hi
    Not sure it will help. Please  check the link below.
    [http://www.sapfans.com/forums/viewtopic.php?f=23&t=40365]
    ~~~Ganesh Kumar K.

Maybe you are looking for

  • Error after Deploying a new Entity Service

    After deploying an entity service and testing it via the testtool the following error occured. Do you have an idea about the reason for this strange behaviour? Thanks in advance. ERROR. Exception thrown in method create. The transaction is marked for

  • Mapping with multiple Adaptive rfc's

    Hi Experts, i have 4 radio buttons, i need to create a single adaptive rfc model, to which i need to create a one ECC system rfc and APO system rfc(multiple backend systems). how to add  the two rfc systems of logical system name to a single logical

  • Trouble to invoke BPEL from Java Client following rmi example

    I still have troubles to invoke my BPEL process from Java Client by following tutorial sample of 102.InvokingProcesses/rmi . I created my Java class within NetBeans IDE. And the following line of code return null for url, java.net.URL url = ClassLoad

  • Streaming radio on my site

    how to put a radio station playing on my flash site? his there anyway to put a online radio station (or several) playing on my flash site, streaming? with simple buttons that stops and starts the radio, volume control and buttons to change the statio

  • WebCenter Framework Doesn't Seem to be present after install

    Hello. I recently created a Web Center Application on JDeveloper and I would like to push this out to another Weblogic 10.3 server I have running Oracle Directory Services 11G. I install WebCenter onto the weblogic server in the same middleware home