Hi,

check the format of inserted date field (should be #08/12/2001# for
example, or #08.12.2001#). It depends on your windows regional
settings. Try to printout result insert SQL and execute it in MS
ACCESS as query.

Dalibor


______________________________ Reply Separator _________________________________
Subject: RE: Using Tomcat with MSAccess
Author:  [EMAIL PROTECTED] ("Greg Trasuk" <[EMAIL PROTECTED]>)
at INTERNET
Date:    9.8.2001 0:08





For what's happening now, you need to print out the SQL, make sure it's
syntactically correct, and print out the exception message that's returned.
Don't know if it's just me, but I find that I tend to make really dumb SQL
errors For later, you should ask yourself what will happen when "Patrick
O'Reilly" tries to register?

Also, when you're doing string comparisons, you should get into the habit of
using
     "".equals(passwd)
rather than
     passwd.equals( "" )

It looks a little strange, but will behave correctly if passwd happens to be
null (if for instance your page was called from an HTML file that  did not
include the passwd field in the form).

Cheers,

Greg Trasuk, President
StratusCom Manufacturing Systems Inc. - We use information technology to
solve business problems on your plant floor.
http://stratuscom.ca

> -----Original Message-----
> From: Jeffrey Worst [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 03, 2001 10:09 PM
> To: [EMAIL PROTECTED]
> Subject: Using Tomcat with MSAccess
>
>
> I'm writing an applet using Tomcat to register new members
> for a library.
> Everything works fine until I get to the part where the new
> information is
> being inserted into the MSAccess DB.  I have commented below
> where the error
> occurs.  Any help would be appreciated.
>
> Thanks,
>
> Jeff
> ------------------
> //New member registration
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.util.*;
> import java.sql.*;
>
> public class NewMember extends HttpServlet {
>    private Statement statement = null;
>    private Connection connection = null;
>    String url = "jdbc:odbc:NewMember";
>    String username="";
>    String password="";
>
>    public void init( ServletConfig config )
>       throws ServletException
>    {
>       super.init( config );
>
>       try {
>          Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
>          connection =
>             DriverManager.getConnection( url, username, password );
>       }
>       catch ( Exception e ) {
>          e.printStackTrace();
>          connection = null;
>       }
>    }
>
>    public void doPost( HttpServletRequest req,
>                        HttpServletResponse res )
>       throws ServletException, IOException
>    {
>       String passwd, member_type, fname, mname, lname, address1,
>           address2, city, zip, country, home_phone, work_phone, email,
> member_since, remarks;
>
>       passwd= req.getParameter( "passwd" );
>       member_type = req.getParameter( "member_type" );
>       fname = req.getParameter( "fname" );
>       mname = req.getParameter( "mname" );
>       lname = req.getParameter( "lname" );
>       address1 = req.getParameter( "address1" );
>       address2 = req.getParameter( "address2" );
>       city = req.getParameter( "city" );
>       zip = req.getParameter( "zip" );
>    country = req.getParameter( "country" );
>       home_phone = req.getParameter( "home_phone" );
>       work_phone = req.getParameter( "work_phone" );
>       email = req.getParameter( "email" );
>       member_since = req.getParameter( "member_since" );
>       remarks = req.getParameter( "remarks" );
>
>       PrintWriter output = res.getWriter();
>       res.setContentType( "text/html" );
>
>       if ( passwd.equals( "" ) ||
>            fname.equals( "" ) ||
>            lname.equals( "" ) ) {
>          output.println( "<H3> Please click the back " +
>                          "button and fill in all " +
>                          "fields.</H3>" );
>          output.close();
>          return;
>       }
>
>    //Below is where the problem occurs.  I get the HTML
> message below of "An
> error occured..."
>    //I think the insertIntoDB method is not working.  It's
> being inserted
> into a MSAccess DB
>    //which has been registered.
>
>       boolean success = insertIntoDB("'" + passwd + "','" +
> member_type +
> "','" + fname + "','" +
>       mname + "','" + lname + "','" + address1 + "','" +
> address2 + "','" +
> city + "','" + zip + "','" +
>       country + "','" + home_phone + "','" + work_phone +
> "','" + email +
> "','" + member_since +
>        "','" + remarks + "'" );
>
>       if ( success )
>          output.print( "<H2>Thank you " + fname +
>                        " for registering.</H2>" );
>       else
>          output.print( "<H2>An error occurred. " +
>                        "Please try again later.</H2>" );
>
>       output.close();
>    }
>
>    private boolean insertIntoDB( String stringtoinsert )
>    {
>       try {
>          statement = connection.createStatement();
>          statement.execute(
>             "INSERT INTO NewMember values (" +
>             stringtoinsert + ");" );
>          statement.close();
>       }
>       catch ( Exception e ) {
>          System.err.println(
>             "ERROR: Problems with adding new entry" );
>          e.printStackTrace();
>          return false;
>       }
>
>       return true;
>    }
>
>    public void destroy()
>    {
>       try {
>          connection.close();
>       }
>       catch( Exception e ) {
>          System.err.println( "Problem closing the database" );
>       }
>    }
> }
>


Reply via email to