• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet ,databases & javaMail

clyde melly
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • 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
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
PrintWriter out = res.getWriter();
System.out.println("str1 : "+str1);
Connection con=DriverManager.getConnection("jdbc dbc:agent");
Statement stmt=con.createStatement();

ResultSet rs=stmt.executeQuery("Select * from "+str1+" ");
}catch(Exception e){System.out.println("E is "+e.toString());}
The html file:
<body bgcolor="#ccffff">
<form action="http://localhost:8080/servlet/agentjdbcServlet" method="post"/>
<input type="text" name="tt"/>
<input type="submit" value="Yes"/>
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);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
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.setContent(message, "text/plain");
static public void main(String g[])
Mail m=new Mail();
}catch(Exception e){}
Mark Spritzler
Posts: 17309
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
[ September 25, 2003: Message edited by: Mark Spritzler ]
clyde melly
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
c'mon guys help me out.Let me know where am i going wrong.
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!