dcsimg
URGENT: uploading files and saving to database
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   lisa_oneill
Posted On:   Monday, February 18, 2002 07:27 AM

i am using ms access and i am trying to upload files and text filds and save them to the database directly using sql. i am trying to do this as one jsp page. I am continuelly getting a null pointer exception. I don't know if this is because it is not reading my file in correctly or my sql syntax is wrong. I am new to jsp and i was wondering can anybody please help me???????????? Thank you in advance :) Here is my code: ResultSet rs = null; ServletInputStream ip=request.getInputStream(); byte[] tmpbuffer= new byte[8192]; int length=0; String inputLine=null; boolean proceed =true; length = ip.readLine( tmpbuffer, 0, tmpbuffer.length); inputLine = new Strin   More>>

i am using ms access and i am trying to upload files and text filds and save them to the database directly using sql. i am trying to do this as one jsp page. I am continuelly getting a null pointer exception. I don't know if this is because it is not reading my file in correctly or my sql syntax is wrong. I am new to jsp and i was wondering can anybody please help me???????????? Thank you in advance :)




Here is my code:



ResultSet rs = null;


ServletInputStream
ip=request.getInputStream();

byte[] tmpbuffer= new byte[8192];


int length=0;

String inputLine=null;

boolean proceed =true;

length = ip.readLine( tmpbuffer, 0, tmpbuffer.length);

inputLine = new String (tmpbuffer, 0, length);

String filename =null;

boolean can_write=false;

FileOutputStream tmpfile=new FileOutputStream("tmpf.txt");

int total_bytes=0;

int bytes_read=0;

int k =0;

boolean error=false;



String To=request.getParameter("To");

String From=request.getParameter("From");

String CusRef=request.getParameter("CusRef");

String Date=request.getParameter("Date");

String Time=request.getParameter("Time");

String Problem=request.getParameter("Problem");

String Solution=request.getParameter("Solution");

String Signed=request.getParameter("Signed");



if(To==null)

{
out.println("You have not entered information -To- ");
}

if(From==null)

{
out.println("You have not entered information -From- ");
}

if(CusRef==null)

{
out.println("You have not entered information -Customer Reference- ");
}

if(Date==null)

{
out.println("You have not entered information -Date- ");
}

if(Time==null)

{
out.println("You have not entered information -Time- ");
}

if(Problem==null)

{
out.println("You have not entered information -Probelm- ");
}

if(Solution==null)

{
out.println("You have not entered information -Solution- ");
}



while (proceed)

{
length = ip.readLine( tmpbuffer, 0, tmpbuffer.length);

if(length < 0)
proceed=false;


if(proceed)

{
inputLine = new String (tmpbuffer, 0,length);

StringTokenizer tokenizer=new StringTokenizer(inputLine,";");


while(tokenizer.hasMoreTokens())

{

String subtoken=tokenizer.nextToken();



if(subtoken.startsWith("fil"))

{
filename=subtoken.substring(11,subtoken.length()-3);

can_write=true;


}


if(can_write)

{
if(!inputLine.startsWith("Content") && !inputLine.startsWith("----"))
{


tmpfile.write(tmpbuffer,0,length);
total_bytes+=length;
v
}

}

}
}
}
Class.forName(Dsn);

Connection con=DriverManager.getConnection(url);

ByteArrayInputStream bais = new ByteArrayInputStream(tmpbuffer);

String sql="INSERT INTO Table1(To, From, CusRef, Dtae, Time, Problem, Solution, Signed, FileName) VALUES ('" + To +"', '" + From + "', '" + CusRef + "', '" + Date + "', '" + Time + "', '" + Problem + "', '" + Solution + "', '" + Signed + "', ?)";

try

{

PreparedStatement stmt;

stmt = con.prepareStatement(sql);

int paramindex=1;

stmt.setBinaryStream(paramindex++, bais, tmpbuffer.length);

stmt.executeUpdate();

stmt.close();

}

catch (Exception d)

{

out.println("Error");

out.println(d);

}

con.close();


if(rs.next())

{

response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);

String newLocn = "Done.html";

response.setHeader("Location",newLocn);

}

else

{

out.println("Error
");


}
   <<Less

Re: URGENT: uploading files and saving to database

Posted By:   ivan_siviero  
Posted On:   Monday, February 18, 2002 07:42 AM

can you tell us where the nullpointer is raised ?
About | Sitemap | Contact