Hi,
Could somebody help me?
I tried to create a table in an MS Access mdb using the Servlet Exec, the
Servlet executed without errors but the table was not created. When I
executed the same servlet using the Servletrunner the table was successfully
created.
The code is given below.
Thanks,
Arvind.
/** Createnewtable.java */
import java.sql.*;
public class Createnewtable {
public Createnewtable() {
super();
}
public void Create_newtable() {
String url = "jdbc:odbc:test";
Connection con;
String createnewtable;
System.out.println("Creating the Table");
createnewtable = "create table newtable " +
"(client varchar(20)not null, " +
"dashtype varchar(20) not null, " +
"week int not null, " +
"value1 int not null, " +
"mean int, " +
"uplimit int, " +
"lowlimit int, " +
"weekdate varchar(10) )";
Statement stmt;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url);
stmt = con.createStatement();
stmt.executeUpdate(createnewtable);
System.out.println("Table Created");
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " +
ex.getMessage());
}
}
}
/** End of class */
/** CreateTableServlet.java */
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CreateTableServlet extends HttpServlet {
Createnewtable cnt;
public void init(ServletConfig config)
{
try
{
super.init(config);
cnt = new Createnewtable();
System.out.println("Calling the Create_newtable method ");
cnt.Create_newtable();
}
catch(ServletException se)
{
System.err.println(se.toString());
}
catch(Exception jdbce)
{
System.err.println("Error at connection
:"+jdbce.toString());
}
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body bgcolor=\"white\">");
out.println("<head>");
String title = "Create Table";
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body>");
// note that all links are created to be relative. this
// ensures that we can move the web application that this
// servlet belongs to to a different place in the url
// tree and not have any harmful side effects.
out.println("<h1>" + title + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
/** End of Servlet */
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html