princess18's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Active Members
Active Posts:
79 (0.05 per day)
Joined:
07-December 09
Profile Views:
6,570
Last Active:
User is offline Sep 19 2013 06:45 PM
Currently:
Offline

Previous Fields

Dream Kudos:
0

Latest Visitors

Icon   princess18 has not set their status

Posts I've Made

  1. In Topic: Uplaod image to MySQL using JSP

    Posted 4 Oct 2012

    upload_attach.jsp

    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import ="java.sql.*" %>
    <%@ page import ="javax.sql.*" %>
    <%@ page import ="javax.naming.InitialContext" %>
    <%@ page import ="java.sql.PreparedStatement.*" %>
    <form name="upload1" method=get>
    <%!
    	String url = "jdbc:mysql://localhost:3306/";
    	String dbName = "dbFinals";
    	String driver = "com.mysql.jdbc.Driver";
    	String userName = "root";
    	String password = "";
    %>
    
    <%	
    try
    {
    	String up1=request.getParameter("num");
    	String up2=request.getParameter("attach");
    	java.io.File f=new java.io.File(up2);
    	java.io.FileInputStream fis= new java.io.FileInputStream(f);
    	out.println(up2);
    	
    	Class.forName(driver).newInstance();
    	Connection con = DriverManager.getConnection(url+dbName,userName,password);
    	PreparedStatement pst=con.prepareStatement("insert into tblpic (blah,pic) values(?,?)");
    	pst.setString(1,up1);
    	pst.setBinaryStream(2,fis,(int)f.length());
    	pst.executeUpdate();
    	pst.close();
    	con.close();
    %>
    <center><h3>File Uploaded Successfull</h3></center>
    <%
    }
    catch(Exception e)
    {
    e.printStackTrace();
    %>
    <center><h3>File Does not Uploaded</h3></center>
    
    <%
    }
    %>
    </form>
    </html> 
    
    




    attach.jsp

    <html>
    <head>
    <title>Attach</title>
    </head>
    <body>
    <br />
    <br />
    <br>
    <center>
    <form name="attach" action="./upload_attach.jsp" method="post" ENCTYPE="multipart/form-data">
    <p><b>Upload No:</b><input type="text" name=num size=30> </p>
    <p><input type="file" name=attach size=30> </p>
    <br />
    <br>
    <input type="submit" name="upl" value="UPLOAD">
    </form>
    </center>
    </body>
    </html> 
    
    



    Why is it not saving in database? Please help me. Thank you!
  2. In Topic: Uplaod image to MySQL using JSP

    Posted 3 Oct 2012

    This is my code.

    <%@page import="java.sql.*,java.io.*"%>
    <%
    try{
        InputStream sImage;
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbfinals","root","");
          Statement st=con.createStatement();
          ResultSet rs=st.executeQuery("SELECT pic FROM tblpic");
          if(rs.last()) {
          byte[] bytearray = new byte[1048576];
          int size=0;
          sImage = rs.getBinaryStream(1);
          response.reset();
          response.setContentType("image/jpeg");
          while((size=sImage.read(bytearray))!= -1 ){
          response.getOutputStream().write(bytearray,0,size);
       }
    }
     con.close();
    }     
    catch(Exception ex){
    out.println("error :"+ex);
    }
    %>
    
    


    However, it gives this error:

    HTTP Status 500 - java.lang.IllegalStateException: getOutputStream() has already been called for this response
    
    type Exception report
    
    message java.lang.IllegalStateException: getOutputStream() has already been called for this response
    
    description The server encountered an internal error (java.lang.IllegalStateException: getOutputStream() has already been called for this response) that prevented it from fulfilling this request.
    
    exception
    
    org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:585)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:465)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    
    root cause
    
    java.lang.IllegalStateException: getOutputStream() has already been called for this response
    	org.apache.catalina.connector.Response.getWriter(Response.java:636)
    	org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:214)
    	org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
    	org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
    	org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:190)
    	org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:126)
    	org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:80)
    	org.apache.jsp.view_jsp._jspService(view_jsp.java:98)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    
    


    Please help me in solving this... :(
  3. In Topic: Uplaod image to MySQL using JSP

    Posted 2 Oct 2012

    I already got it. Thank you very much!!! :D
  4. In Topic: Uplaod image to MySQL using JSP

    Posted 2 Oct 2012

    But I stored it in a uid variable. Isn't that possible? How can I solve this? Please help me...

    I've modified the code to this:

    queryString = "select * from tbluser where uname=? and upass=? and eadd=?";
    				ps = conn.prepareStatement(queryString);
    				ps.setString(1, uname);
    				ps.setString(2, pass);
    				ps.setString(3, eadd);
    				rs = ps.executeQuery();
    				if (rs.next())
    				{
    						int UID=rs.getInt(1);
    						out.println(UID);
    				}
    				
    
    				queryString = "INSERT INTO tbluserperinfo (fname,mname,lname,gender,mstat,age,bday,pobirth,religion,citizenship,cadd,padd,country,conno,talskills) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    			    ps = conn.prepareStatement(queryString);
    				ps.setInt(1, UID);
    				ps.setString(2, fname);
    				ps.setString(3, mname);
    				ps.setString(4, lname);
    
    
    


    However, the error is still the same. :(
  5. In Topic: Uplaod image to MySQL using JSP

    Posted 2 Oct 2012

    
    queryString = "select * from tbluser where uname=? and upass=? and eadd=?";
    				ps = conn.prepareStatement(queryString);
    				ps.setString(1, uname);
    				ps.setString(2, pass);
    				ps.setString(3, eadd);
    				rs = ps.executeQuery();
    				while (rs.next())
    				{
    						int UID=rs.getInt(1);
    						out.println(UID);
    				}
    			
    				queryString = "INSERT INTO tbluserperinfo VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    			    ps = conn.prepareStatement(queryString);
    				ps.setInt(1, UID);
    				ps.setString(2, fname);
    				ps.setString(3, mname);
    				ps.setString(4, lname);
    
    
    


    This is my code. I wonder why I always get this error:
    Unable to compile class for JSP: An error occurred at line: 80 in the jsp file: /SaveRegForm.jsp UID cannot be resolved to a variable 77: 78: queryString = "INSERT INTO tbluserperinfo VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; 79: ps = conn.prepareStatement(queryString); 80: ps.setInt(1, UID); 81: ps.setString(2, fname); 82: ps.setString(3, mname); 83: ps.setString(4, lname); Stacktrace:
    
    description The server encountered an internal error (Unable to compile class for JSP: An error occurred at line: 80 in the jsp file: /SaveRegForm.jsp UID cannot be resolved to a variable 77: 78: queryString = "INSERT INTO tbluserperinfo VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; 79: ps = conn.prepareStatement(queryString); 80: ps.setInt(1, UID); 81: ps.setString(2, fname); 82: ps.setString(3, mname); 83: ps.setString(4, lname); Stacktrace:) that prevented it from fulfilling this request.
    


    Please help me.... Thank you!

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

Page 1 of 1
  1. Photo

    samadalove Icon

    20 Jul 2012 - 03:36
    Hello dearest
    My name is Miss Samada
    How are you? I Hope you are fine and in perfect Health.i came across your profile today and deemed it necessary to write you immediately. Am too curious to know you more. Could you please reciprocate to my message by dropping mail on my contact email (Samada4love88@yahoo.com) so we can introduce our self better on media and also share the passion ...
  2. Photo

    vbVirgin Icon

    05 Sep 2011 - 21:23
    hey... princess i really kinda need your code about traffic light.. our prof is kinda stupid he doesnt teaches us right.. i really need your codes..
  3. Photo

    bidemop Icon

    27 Jan 2011 - 21:32
    princess, I need your help. you posted about a stoplight a while back. do you still have that code?
Page 1 of 1