• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet ,databases & javaMail

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Write a Servlet to do the following:
The Database name will be supplied in the parameter dbname - this will be passed using either the Get or Post methods so your servlet should cater for both
Check for the existence of the MS Access database table agents and if it exists, delete it
Create a Database table as follows:
table name: agents
field: eno numeric
field: trregion alphanumeric
field: trcountry alphanumeric

If the Servlet encounters any errors it should email details of the errors, including a complete stack trace as follows:
EMAILED from the server to the account xyz@yyy.net, the from address should be abc@yyy.net, the subject should be "Table Creation Failed"
The body should contain a summary of the error.
The stack trace should be attached to the email as an ASCII text file.
1.For the first part I tried using
if(rs.next()){drop table agents;} where rs is the resultset.
Although the table agents get deleted if it exists,but ( java.sql.SQLexception : No ResultSet was produced)
is thrown.Is there any other way out?

2.For the second part I get an SQLException with the following code when I pass the path
("c:\agentpro.mdb") for the input parameter "tt".How do i retrieve the agents table which is in agentpro.mdb,so that I can use it in my
program.
the code :
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class agentjdbcServlet extends HttpServlet
{
String str,str1;
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws IOException, ServletException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
str1=req.getParameter("tt");
System.out.println("str1 : "+str1);
out.println("melly");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc dbc:agent");
Statement stmt=con.createStatement();

ResultSet rs=stmt.executeQuery("Select * from "+str1+" ");
while(rs.next())
{
str=rs.getString(1);
System.out.println(str);
}
rs.close();
stmt.close();
con.close();
}catch(Exception e){System.out.println("E is "+e.toString());}
}
}
The html file:
<html>
<body bgcolor="#ccffff">
<form action="http://localhost:8080/servlet/agentjdbcServlet" method="post"/>
<input type="text" name="tt"/>
<br><br/>
<input type="submit" value="Yes"/>
</body>
</html>
3 For the third part I am using JavaMail Api.I am just working on this part.
How do I go about the error and attachment stuff.
the code:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class Mail
{
public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "ABC");
// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);

// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
static public void main(String g[])
{
Mail m=new Mail();
try
{
m.postMail("abc@yyy.net","Hi","Ok","xyz@yyy.com",ServerName);
}catch(Exception e){}
}
}
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Clyde.
Please refrain from cross posting the same question in two different forums.
Also there is a CODE tag that you can place around your code that will keep everything looking really clean, with your indentation and everything. It makes posts more readable.
Here's an example using the
See how much cleaner that looks when you use the tags?
Well good luck. Unfortunately I don't have a good answer for you in the question you have, it is above my knowledge.
Mark
[ September 25, 2003: Message edited by: Mark Spritzler ]
 
clyde melly
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
c'mon guys help me out.Let me know where am i going wrong.
 
reply
    Bookmark Topic Watch Topic
  • New Topic