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

Similar Messages

  • From an Oracle form, I want to read a text file.

    From an Oracle form, I want to read a text file. In the form on a button press I have:
    declare
    in_file Text_IO.File_Type;
    linebuf VARCHAR2(1800);
    filename VARCHAR2(30);
    BEGIN
    filename:=GET_FILE_NAME('U:\ora_devl\pps\work\a.txt', File_Filter=>'Text Files (*.txt)|*.txt|');
    in_file := Text_IO.Fopen(filename, 'r');
    LOOP
    Text_IO.Get_Line(in_file, linebuf);
    -- :text_item5:=:text_item5||linebuf||chr(10);
    Text_IO.New_Line;
    END LOOP;
    EXCEPTION
    WHEN no_data_found THEN
    Text_IO.Put_Line('Closing the file...');
    Text_IO.Fclose(in_file);
    END;
    It gets an ORA-302000. I suspect the problem starts with the GET_FILE_NAME because when I comment out everything but that, It processes endlessly never ending.
    Forms [32 Bit] Version 11.1.1.3.0 (Production)
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    What can you tell me? Thanks

    GET_FILE_NAME will try to open an "Open File" dialog on the server, which obviously can't happen. If you want to use that type of behavior you need to use WebUtil and the function CLIENT_GET_FILE_NAME. Example:
         filename := CLIENT_GET_FILE_NAME('C:\', File_Filter=> 'Text Files (*.txt)|*.txt|All Files (*.*)|*.*|', dialog_type=> OPEN_FILE);Refer to the Builder Online help for more details. You can also refer to the demo which is available here:
    http://www.oracle.com/technetwork/developer-tools/forms/downloads/index.html
    More information here:
    http://www.oracle.com/technetwork/developer-tools/forms/webutil-090641.html
    Also, it appears that you are attempting to use a mapped drive ("U"). Although this can be made to work, it is not recommended and in some cases will not be supported. If you need access to remote files, you should use some other mechanism to bring the file to the local machine before manipulating it.

  • Reading a text file from a remote host. Authentication required.

    Hi frnds,
    I have to read a text file "config.txt" from a remote host "HOSTNAME". File is shared in a folder - "FOLDER" .
    If the folder is shared with no password protection then it works. But if the folder is password protected the code is unable to read the file.
    I know the UserName and PassWord of the shared folder. How to code for this.
    I don't want to share the Folder to everyone without a password.
    Kindly Help.
    try {
    FileReader fr=new FileReader("\\\\HostName\\folder\\config.txt");
    BufferedReader br=new BufferedReader(fr);
    String s=null;
    while((s=br.readLine())!=null)
    /* One line is read */
    fr.close();
    catch(Exception e)
    throw new Exception("Exception in ConfigConstants."+e.toString());
    urs
    Mishra

    ok.. let me define it clearly...
    By using ftp as a protocol how can I read a text file
    in remote machine........ kindly do reply....Have a look at this article:
    http://www.javaworld.com/javaworld/jw-04-2003/jw-0404-ftp.html
    and what are the prerequisities that are needed for
    such a type of operation.....(At least) an FTP server should be running on the machine where the text file resides.
    Message was edited by:
    prometheuzz
    Oh, you should have your keyboard fixed: the full stop key seems to be stuck, you have a lot of trailing ..... after each sentence.

  • Reading a text file from a URL

    I am having problems trying to read a text file from a URL.
    This is the code i have been using:
    package Java;
    import java.net.*;
    import java.io.*;
    public class Main_1 {
    public static void main(String[] args) throws Exception {
         URL myAddress = new URL("http://www.geocities.com/simonrobinson1/java/farrago.txt");
         BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        myAddress.openStream()));
         String inputLine;
         while ((inputLine = in.readLine()) != null)
         System.out.println(inputLine);
         in.close();
    but it returns an error saying:
    java.net.NoRouteToHostException: Operation timed out: no further information
    at java.net.PlainSocketImpl.socketConnect(Native Method) .....etc etc.
    Is this just a problem due to my network or is there something wrong with my code ????

    Altho you can access the file by typing the URL in a browser, geocities being a free web-hosting service don't like you to access the materials without seeing their ads. You have to find a way to trick it into thinking that you are indeed coming in from a web browser even tho you aren't.
    V.V.

  • Read a text file from DB directly (don't use PLSQL).

    how can I Read a text file from DB directly (don’t use PLSQL). ?

    If there is a known structure, you could use External Table access and query that "file" as any table.
    Nicolas.

  • How to read two text files using the Read from spreadsheet.vi and then plot it

    I need to read two text files using the read from spreadsheet function and then plot these files over time.
    The file with the .res extention is the RMS values (dt and df) and the second file contains the amplitude of a frequency spectrum.
    I really appreciate any help..thanks
    Attachments:
    RMS.txt ‏1 KB
    FREQUENCY.txt ‏1 KB

    From NI Example Finder:
    Write to Text File.vi
    Read from Text File.vi
    Jean-Marc
    LV2009 and LV2013
    Free PDF Report with iTextSharp

  • How to read a text file from a Jar file

    Hi
    How can I read a text file from a Jar file?
    Thanx in advance..

    thanx
    helloWorld it works.damn, I didn't remove it fast enough. Even if it is urgent, it is best not to mention it, telling people just makes them take longer.

  • Read a text file and populate table

    My email addres is [email protected]
    I am new to java. My project requires me to read a text file and pick some values from the text file and populate a table in MS Access. The main fields are from the TEXT. Some of the columns to be read are:
    Transaction ref.
    Amount
    User ref.
    Date
    The text file is as follows:
    Receiver =
    FBNINGLAXXX LT : A
    FST BANK OF NIGERIA PLC
    LAGOS
    LAGOS
    NG
    NIGERIA
    Transaction ref. = SPLOUK01P0008888 Related ref. = 00077003
    Amount = 16675750, NGN Value/Date =
    Format & Validation
    Version = 0205 Checked = Minimum
    Netw. Appl. = FIN Passed = Minimum
    Sender to Receiver Instructions
    Banking Prior. = User ref. = SPLOUK01P0008888
    Warning Status =
    Possible Duplicate Emission
    Appl/Serv = SWIFT Interface
    RP & Ft = SIfrom_SWIFT
    Date/Time = 01/04/03 18:53:19
    Text =
    :20:SPLOUK01P0008888
    :28D:1/1
    :30:030401
    :21:00077003
    :32B:NGN16675750,00
    :50H:/4072010014877
    SPDC FBN East Main A/C
    :57D:WEMA BANK PLC
    PLOT 22 TRANS-AMADI BRANCH P.H.
    PORT HARCOURT.
    RIVERS STATE.
    :59:/0421002101818
    PROJECT MASTERS NIGERIA LTD.
    C101 ELIOGBOLO VILLAGE OFF
    EAST-WEST ROAD RUMUOKORO PORT HAR
    COURT
    :70:PM PCE-TS 03 001030226
    :71A:OUR
    Block 5:
    {MAC:9F664844}{CHK:60EF6513E579}
    Message History =
    *Original (Completed)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    See in this case as you are dealing with Files and database. you need read the File by using the I/O Streams. if you have to select some particular values you can go Random access file.Once you have retrived values. You can go for the second part that is make a jdbc connection to database, and use simple SQL statements to populate those values into the table.
    How this will give you a better picture

  • Text File Database

    Hello,
    i am a student at The Open University "APEIRON" Travnik (www.out.edu.ba), i am pursuing a Masters degree in IT, we have one Exam called Java programming.
    My practical exam part is to create a program that should enable user to manipulate students grades. The app should allow these options:
    - Read students data,
    Read students data, needs to ask a user for students name and some ID (Surname etc.), and after that lists students grades and Courses.
    - Inserting of new grades,
    Inserting of new grades should have option to insert a new Course name, students name and grade for that Course.
    - Change of existing grades.
    Change of existing grades needs to ask for students name and/or ID, surname and the name of a Course and shows his present grade, Then it should have an option to change students grade for that Course.
    For this App all of validations should be done.
    All of the data (students names, Course names, Grades etc.), needs to be stored in text file database?! Now, i am a newb to Java, but i worked before with VB, and SQL, and i saw there are some similarities to acces and modify data in SQL database. But the problem is, i never worked with Flat text file databases and now i am stuck, i do not even know how to create a text database or even to connect Java to that database.
    Please, if anyone can help me i would be very grateful!?

    HaloOo wrote:
    i am pursuing a Masters degree in ITPursuing as in commencing, or pursuing as in first/second year undergraduate student. If the former then I am abit worried at your lack of prior research (or is this how you research).
    Please, if anyone can help me i would be very grateful!?You will need to invest some time in the basics of programming in Java and OOL. There are multiple tutorials available on reading/writing to text files. One thing to note: a text file is treated in the majority of cases like a wipe board. You can write a whole bunch of stuff on it, but if you decide you want to write a line in the middle, then unfortunately you need to read what is currently on the whiteboard, rewrite it, append your new message, then append the remainding text from the white board. IMHO a (RAF) is not applicable in this situation.
    Task1: Java: hello world
    Task2: Introductory tutorials
    Task3: Read a text file/write a text file/display contents of file
    You choose,
    Mel

  • Powershell script - how to read a registry hive and store the value in text file and then again read the text file to write the values back in registry

    Hi All,
    powershell script Method required to read a value from registry and then taking the backup of that values in some text file.
    For example the hive is
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path
    and under path i need to take back up  of values in some text file and then put some value in the registry after back is taken in text file.
    Also how to read the text file values so that we can again write to registry hive  back from the back up text file.
    Your help is much appreciated.
    Umeed4u

    I think you need to read this first:
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/a0def745-4831-4de0-a040-63b63e7be7ae/posting-guidelines?forum=ITCG
    Don't retire TechNet! -
    (Don't give up yet - 12,830+ strong and growing)

  • I would like to read a text file in which the decimal numbers are using dots instead of commas. Is there a way of converting this in labVIEW, or how can I get the program to enterpret the figures in the correct way?

    The program doest enterpret my figures from the text file in the correct way since the numbers contain dots instead of commas. Is there a way to fix this in labVIEW, or do I have to change the files before reading them in the program? Thanks beforehend!

    You must go in the labview option menu, you can select 'use the local
    separator' in the front side submenu (LV6i).
    If you use the "From Exponential/Fract/Eng" vi, you are able to select this
    opton (with a boolean) without changing the labview parameters.
    (sorry for my english)
    Lange Jerome
    FRANCE
    "Nina" a ecrit dans le message news:
    [email protected]..
    > I would like to read a text file in which the decimal numbers are
    > using dots instead of commas. Is there a way of converting this in
    > labVIEW, or how can I get the program to enterpret the figures in the
    > correct way?
    >
    > The program doest enterpret my figures from the text file in the
    > correct way since the numbers contain dots instea
    d of commas. Is there
    > a way to fix this in labVIEW, or do I have to change the files before
    > reading them in the program? Thanks beforehend!

  • How do I read a text file in a Jar Executable?

    Hello All,
    I have a need to package a text file into a Jar Exectable file and then have my java code read that text file in using a BufferedReader. Can anyone out there tell me how to do this? My first question is how do I reference this file by the path name? O, I'm also using Windows.
    Thanks for your help.
    Karl

    I have the same problem with kportner . I did by joop_eggen but I got the error at:
    BufferedReader in = new InputStreamReader(is);Can't conver from BufferedReader to InputStreamReader
    When I up my applet to server and get it from client. My applet couldn't read the text file.
    Any one help me!
    Thanks.

  • How can i read the text files and buffer the data in Vector?

    hi. I have been running into this problem for days, but with no luck and losing right direction.
    The problem is : I am trying to read a text file and buffer the data into a
    Queue for each user.
    the sample text file is as below:( 1st column is timestamp, 2nd is user_id, 3rd is packet_id, 4th is packet_seqno, 5th is packet_size)
    0 1 1 1 512
    1 2 1 2 512
    2 3 1 3 512
    3 4 1 4 512
    4 5 1 5 512
    5 6 1 6 512
    6 7 1 7 512
    7 8 1 8 512
    8 9 1 9 512
    9 10 1 10 512
    10 1 2 11 512
    11 2 2 12 512
    12 3 2 13 512
    13 4 2 14 512
    14 5 2 15 512
    15 6 2 16 512
    16 7 2 17 512
    17 8 2 18 512
    18 9 2 19 512
    19 10 2 20 512
    20 1 3 21 512
    21 2 3 22 512
    22 3 3 23 512
    23 4 3 24 512
    24 5 3 25 512
    25 6 3 26 512
    26 7 3 27 512
    27 8 3 28 512
    28 9 3 29 512
    29 10 3 30 512
    30 1 4 31 512
    31 2 4 32 512
    32 3 4 33 512
    33 4 4 34 512
    34 5 4 35 512
    35 6 4 36 512
    36 7 4 37 512
    37 8 4 38 512
    38 9 4 39 512
    39 10 4 40 512
    40 1 5 41 512
    41 2 5 42 512
    42 3 5 43 512
    43 4 5 44 512
    44 5 5 45 512
    45 6 5 46 512
    46 7 5 47 512
    47 8 5 48 512
    48 9 5 49 512
    49 10 5 50 512
    50 1 6 51 512
    51 2 6 52 512
    52 3 6 53 512
    53 4 6 54 512
    54 5 6 55 512
    55 6 6 56 512
    56 7 6 57 512
    57 8 6 58 512
    58 9 6 59 512
    59 10 6 60 512
    60 1 7 61 512
    61 2 7 62 512
    62 3 7 63 512
    63 4 7 64 512
    64 5 7 65 512
    65 6 7 66 512
    66 7 7 67 512
    67 8 7 68 512
    68 9 7 69 512
    69 10 7 70 512
    70 1 8 71 512
    71 2 8 72 512
    What I wanna do is to read all the data above and buffer them in a queue for each user( there are only 10 users in total).
    I already created a class called Class packet:
    public class packet {
        private int timestamp;
        private int user_id;
        private int packet_id;
        private int packet_seqno;
        private int packet_size;
        /** Creates a new instance of packet */
        public packet(int timestamp,int user_id, int packet_id,int packet_seqno, int packet_size)
            this.timestamp = timestamp;
            this.user_id=user_id;
            this.packet_id=packet_id;
            this.packet_seqno=packet_seqno;
            this.packet_size=packet_size;
    }then I wanna to create another Class called Class user which I can create a queue for each user (10 users in total) to store type packet information. the queue for each user will be in the order by timestamp.
    any idea and sample code will be appreciated.

    Doesn't sound too hard to me. Your class User (the convention says to capitalize class names) will have an ArrayList or Vector in it to represent the queue, and a method to store a Packet object into the List. An array or ArrayList or Vector will hold the 10 user objects. You will find the right user object from packet.user_id and call the method.
    Please try to write some code yourself. You won't learn anything from having someone else write it for you. Look at sample code using ArrayList and Vector, there's plenty out there. Post in the forum again if your code turns out not to behave.

  • Difference in reading a text file in Windows & Unix

    I have a code which is working fine in windows but is stopping after reading the first line of a text file in
    Unix. The code is something like below:-
    declare
    file_handle text_io.file_type; /*running form*/
    filename varchar2(60);
    v_line varchar2(200);
    begin
    message('before fopen');
    filename:=:file_name;message(filename);
    file_handle:=text_io.fopen(filename,'R');
    loop
    begin
    text_io.get_line(file_handle,v_line);
    --:line:=v_line;
    exception
    when no_data_found then
    text_io.fclose(file_handle);
    message('NO MORE DATA IS FOUND ');
    temp:='stop';
    exit;
    when others then
    text_io.fclose(file_handle);
    message('ERROR ');
    exit;
    end;
    mob_no:=substr(v_line,1,10);
    begin
    message(' Mobile NO is '||mob_no);
    message(' Mobile NO is '||mob_no);
    exit when temp='stop';
    end loop;
    commit;
    message('File SUCCESSFULLY LOADED........');
    message('File SUCCESSFULLY LOADED........');
    end;
    Is there any difference in reading a text file in Windows & Unix.
    I hope, my question is clear. Please help in solving the doubt as it is urgent.
    Regards.

    There is no difference in reading a file - you use TEXT_IO in the normal way. However there is of course a difference in the format of text files between Unix and Dos so if you had say transferred your test file from Dos to the Unix box for testing strange things might happen if you had not transferred in ASCII mode.

  • How to read a text file using Java

    Guys,
    Good day!
    Please help me how to read a text file using Java and create/convert that text file into XML.
    Thanks and God Bless.
    Regards,
    I-Talk

         public void fileRead(){
                 File aFile =new File("myFile.txt");
             BufferedReader input = null;
             try {
               input = new BufferedReader( new FileReader(aFile) );
               String line = null;
               while (( line = input.readLine()) != null){
             catch (FileNotFoundException ex) {
               ex.printStackTrace();
             catch (IOException ex){
               ex.printStackTrace();
         }This code is to read a text file. But there is no such thing that will convert your text file to xml file. You have to have a defined XML format. Then you can read your data from text files and insert them inside your xml text. Or you may like to read xml tags from text files and insert your own data. The file format of .txt and .xml is far too different.
    cheers
    Mohammed Jubaer Arif.

Maybe you are looking for

  • Exchange Server 2013 and RADIUS server(freeRADIUS2)

    I am a student and doing an internship. I have to test Microsoft Exchange Server 2013. I am using Windows Server 2012, I already installed Exchange Server 2013 on it and everything works as intended. But I couldn't find out how to configure my Window

  • Migration of Forms6i to oracle 10g

    We have some D2k applications and we need to migrate from forms6i(Client Server) to webForms (oracle 10g). i have downloaded Oracle Application Server 10g Release 2 (10.1.2.0.2). and tried installing it on VISTA 32 bit. But it is showing me Operating

  • Source List Required in Extended Classic

    Hi, We have a requirement wherein a Source List is required which contains the R3 contract. Now, when a PO is created in SRM, the source should pick up the contract based on the vendor list and the contract number and then this should also update the

  • Shared Services Mixed Native-MSAD group nesting

    Is anyone doing this? I am trying to make an MSAD group a member of a native group using shared services and after adding the MSAD group, the console errors out for the group i just made whenever trying to view the group members. This is repeatable a

  • Uninstalling and then reinstalling

    I need to reformat and reinstall Snow Leopard on my iMac. What do I need to do to uninstall Photoshop CS4, ACR and Bridge to ensure there are no problems with the licences when I reinstall them later? Thanks. Stephen