upload a text file into database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjay_scjp
    New Member
    • Aug 2006
    • 1

    #1

    upload a text file into database

    Hi,
    I want to save a file into databse how can it is possible ?

    Can any one help me to make codes in jsp. the codes require for upload a text file into database

    Rgds
    SanJay
  • nehacredo
    New Member
    • May 2007
    • 5

    #2
    dis jsp code help u for uploading text into database

    <%@ page import="java.sq l.*"%>
    <%@ page import="java.io .*"%>
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <%
    try
    {
    String name;
    String address;
    String path;
    name=request.ge tParameter("nam e");
    address=request .getParameter(" address");
    File image=new File(request.ge tParameter("ima ge"));
    path=request.ge tParameter("ima ge");
    Class.forName(" com.mysql.jdbc. Driver");
    Connection con=DriverManag er.getConnectio n("jdbc:mysql ://localhost:3306/sushikha","root ","root");
    PreparedStateme nt pstmt=con.prepa reStatement("in sert into pro(name,addres s,data,path) values(?,?,?,?) ");
    pstmt.setString (4,path);
    pstmt.setString (1,name);
    pstmt.setString (2,address);
    InputStream is=new FileInputStream (image);
    //FileReader is = new FileReader(imag e);

    pstmt.setBinary Stream(3, is, (int)(image.len gth()));
    int s=pstmt.execute Update();
    if(s>0)
    {
    out.println("Up loaded");
    }
    else
    {
    %>
    unsucessfull
    <%}
    is.close();
    pstmt.close();
    }
    catch(Exception e)
    {
    }%>
    </body>
    </html>

    neha........... .......

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      thanxxxx nehacredo u solved the problem.

      first of all this is JS/AJAX forum so u should suggest the sanjay_scjp to post the code to JAVA forum.

      one more thing ..... u should not send the whole code like this.
      let him or her do it first.... then where he or she facing problem just to that point u should help.
      actually i also in the begining .. requested for code but the experts told me that do it first urself then come here with ur particular problem.
      because in this way i learnt a lot from this site.
      thanx to TSDN to help me......
      sorry to say .. but that's true story frnd.

      kind regards.
      dmjpro.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Moved to Java forum.

        Comment

        • jeffponder
          New Member
          • Jul 2008
          • 3

          #5
          hi guys i will like to know how to upload a file and save into the database phpmyadmin but its really getting me confused..and also want to view the content of the file saved.
          thanks
          jeffponder

          Comment

          • jeffponder
            New Member
            • Jul 2008
            • 3

            #6
            i want to know how to upload a text file into the database and also view the content been saved

            Comment

            • jeffponder
              New Member
              • Jul 2008
              • 3

              #7
              please i really need an asistance on how to upload a text file into the database where phpmyadmin is the database i use and also view the content..please if any solution it should be sent to my mail [DELETED]
              thanks
              Last edited by RedSon; Jul 23 '08, 05:27 PM. Reason: NO EMAIL

              Comment

              • RedSon
                Recognized Expert Expert
                • Jan 2007
                • 4980

                #8
                jeffponder,

                Do not post your email in threads. Do not hijack another person's thread with your own problems/questions. If you have a similar question you can create another thread and link to this one.

                Please read the posting guidelines located at the top of the screen under help.

                -RedSon

                Comment

                Working...