RE: Using Tomcat with MSAccess

2001-08-09 Thread William Kaufman

This is pretty far off the topic of servlets--sorry to have added to it.
But you can get the source for String.java (and most of the java.* packages)
in the JDK, in a file called src.jar.

Suffice it to say that, since String.equals() checks for pointer equality
and object type, then downcasts, and then compares lengths,

  String foo;

  if ("".equals(foo)) ...

will never be faster than,

  if (foo != null && foo.length() == 0)

since equals() does the exact same thing, plus some (possibly ellided) type
comparison and downcasting.

Plus, it's rarely what you want: most of the time, you want to treat empty
string and null the same, and non-empty strings differently.  So you
actually want,

  if (foo == null || foo.length() == 0)

But, if you were testing for a _specific_ string,

  if ("Test Me".equals(foo))

_is_ a nice short-hand that avoids testing for null first.  It's still
slower in the case of a null string, than,

  if (foo != null && foo.equals("Test Me"))

for the reasons listed above; but it's better for non-null strings, and it's
at least as easy to understand.

-- Bill K. 

> -Original Message-
> From: Beth Kelly [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 09, 2001 9:50 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Using Tomcat with MSAccess
> 
> 
> 
> Kyle Wayne Kelly
> (504)391-3985
> http://www.cs.uno.edu/~kkelly
> - Original Message -
> From: "William Kaufman" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, August 09, 2001 7:14 AM
> Subject: RE: Using Tomcat with MSAccess
> 
> 
> > > 
> > > > > "".equals(passwd)
> > > > > rather than
> > > > > passwd.equals( "" )
> > > 
> > > > No you shouldn't. That's totally evil. For a start, you're
> > > > creating another String object by doing ""
> > > 
> > > 
> > >   As "" is a constant string, it is created just once. So there
> > >   is not much overhead.
> >
> > True, other than the overhead of calling String.intern() 
> when the class is
> > loaded (JLS 3.10.5).
> >
> > >   ("".equals might be even faster, because
> > >   the jit can inline the method call, as the address of the object
> > >   and the equals method is constant in this case.
> >
> > False.  If the compiler can inline equals(), it can inline 
> length(), too.
> > (In fact, it's more likely to inline length(), since it's a 
> far simpler
> > method.)
> I wonder if equals() is implemented with a bitwise "and".  If 
> that were the
> case, then the first invocation of equals would be simpler 
> than the length
> method (that is with delayed lazy evaluation).
> >
> > (And take a look at the source for String.equals(): at best, with
> comparable
> > inlining of the two methods, you've added an "instanceof" 
> and a downcast,
> > which likely swamps any time taken for the rest of the comparison.)
> >
> > -- Bill K.
> 
> 



Re: Using Tomcat with MSAccess

2001-08-09 Thread Kyle Wayne Kelly

I was talking about "String.equals()".
Kyle Wayne Kelly
(504)391-3985
http://www.cs.uno.edu/~kkelly
- Original Message -
From: "Beth Kelly" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, August 09, 2001 9:50 AM
Subject: Re: Using Tomcat with MSAccess


>
> Kyle Wayne Kelly
> (504)391-3985
> http://www.cs.uno.edu/~kkelly
> - Original Message -
> From: "William Kaufman" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, August 09, 2001 7:14 AM
> Subject: RE: Using Tomcat with MSAccess
>
>
> > > 
> > > > > "".equals(passwd)
> > > > > rather than
> > > > > passwd.equals( "" )
> > > 
> > > > No you shouldn't. That's totally evil. For a start, you're
> > > > creating another String object by doing ""
> > > 
> > > 
> > >   As "" is a constant string, it is created just once. So there
> > >   is not much overhead.
> >
> > True, other than the overhead of calling String.intern() when the class
is
> > loaded (JLS 3.10.5).
> >
> > >   ("".equals might be even faster, because
> > >   the jit can inline the method call, as the address of the object
> > >   and the equals method is constant in this case.
> >
> > False.  If the compiler can inline equals(), it can inline length(),
too.
> > (In fact, it's more likely to inline length(), since it's a far simpler
> > method.)
> I wonder if equals() is implemented with a bitwise "and".  If that were
the
> case, then the first invocation of equals would be simpler than the length
> method (that is with delayed lazy evaluation).
> >
> > (And take a look at the source for String.equals(): at best, with
> comparable
> > inlining of the two methods, you've added an "instanceof" and a
downcast,
> > which likely swamps any time taken for the rest of the comparison.)
> >
> > -- Bill K.
>
>





Re: Using Tomcat with MSAccess

2001-08-09 Thread Beth Kelly


Kyle Wayne Kelly
(504)391-3985
http://www.cs.uno.edu/~kkelly
- Original Message -
From: "William Kaufman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, August 09, 2001 7:14 AM
Subject: RE: Using Tomcat with MSAccess


> > 
> > > > "".equals(passwd)
> > > > rather than
> > > > passwd.equals( "" )
> > 
> > > No you shouldn't. That's totally evil. For a start, you're
> > > creating another String object by doing ""
> > 
> > 
> >   As "" is a constant string, it is created just once. So there
> >   is not much overhead.
>
> True, other than the overhead of calling String.intern() when the class is
> loaded (JLS 3.10.5).
>
> >   ("".equals might be even faster, because
> >   the jit can inline the method call, as the address of the object
> >   and the equals method is constant in this case.
>
> False.  If the compiler can inline equals(), it can inline length(), too.
> (In fact, it's more likely to inline length(), since it's a far simpler
> method.)
I wonder if equals() is implemented with a bitwise "and".  If that were the
case, then the first invocation of equals would be simpler than the length
method (that is with delayed lazy evaluation).
>
> (And take a look at the source for String.equals(): at best, with
comparable
> inlining of the two methods, you've added an "instanceof" and a downcast,
> which likely swamps any time taken for the rest of the comparison.)
>
> -- Bill K.





RE: Using Tomcat with MSAccess

2001-08-09 Thread William Kaufman

> 
> > >   "".equals(passwd)
> > > rather than
> > >   passwd.equals( "" )
> 
> > No you shouldn't. That's totally evil. For a start, you're 
> > creating another String object by doing ""
> 
> 
>   As "" is a constant string, it is created just once. So there
>   is not much overhead.

True, other than the overhead of calling String.intern() when the class is
loaded (JLS 3.10.5).

>   ("".equals might be even faster, because 
>   the jit can inline the method call, as the address of the object 
>   and the equals method is constant in this case.

False.  If the compiler can inline equals(), it can inline length(), too.
(In fact, it's more likely to inline length(), since it's a far simpler
method.)

(And take a look at the source for String.equals(): at best, with comparable
inlining of the two methods, you've added an "instanceof" and a downcast,
which likely swamps any time taken for the rest of the comparison.)

-- Bill K.



RE: Using Tomcat with MSAccess

2001-08-09 Thread Brett Knights

A couple of points:
for your SQL try using a PreparedStatement and using the setXXX methods on it.

Greg's point about Patrick O'Reilly was that with your hardcoded update statement you 
don't have any method of escaping single
quotes in the input data.
Also it looks like you are sending a string where the database likely expects a date 
field.

Also the odbc-jdbc driver is not thread safe. If you have two people registering near 
enough the same time you will have weird hard
to re-produce problems with your servlet.
With your current setup you need to at least modify your InsertIntoDB method so that 
it is synchronized on the connection.

Then you need to find a way to make your servlet re-load the connection if someone 
restarts the access database...

A solution I think tends to work would be to use a ConnectionPool that allows only a 
single connection. You'd get the connection in
your InsertIntoDB method and would no longer need to worry about synchronization. The 
pool should manage re-getting the connection
after an access restart.

HTH

***
Brett Knights 250-338-3509 work
[EMAIL PROTECTED] 250-334-8309 home
***




Re: Using Tomcat with MSAccess

2001-08-09 Thread John Baker

On Thursday 09 August 2001 06:08 am, you wrote:
> 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).

No you shouldn't. That's totally evil. For a start, you're creating another 
String object by doing "", and to add to this, you're saying it's ok to pass 
null to equals. Passing null to the equals method is an awful idea. You 
actually want:

if ((passwd != null) && (passwd.lenght() == 0)) {
   // Then do something
}

That's far nicer, and doesn't put across the impression you don't know what 
you're talking about :-)

> Cheers,
>
> Greg Trasuk, President
> StratusCom Manufacturing Systems Inc. - We use information technology to
> solve business problems on your plant floor.

[ badly, by the looks of it :p ]

> 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( " Please click the back " +
> >  "button and fill in all " +
> >  "fields." );
> >  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( "Thank you

RE: Using Tomcat with MSAccess

2001-08-08 Thread Greg Trasuk

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( " Please click the back " +
>  "button and fill in all " +
>  "fields." );
>  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( "Thank you " + fname +
>" for registering." );
>   else
>  output.print( "An error occurred. " +
>"Please try again later." );
>
>   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()
>{
>  

Re: Using Tomcat with MSAccess

2001-08-04 Thread Randall Parker

You ought to fire up a debugger and debug this. 

Also, you could add some code in your catch to your insert statement that would write 
output to a log file. 

As for MS Access and JDBC: I've had some problems with this where resource leakage 
would eventually cause the JDBC calls to slow to a crawl. I've tried closing every 
resource when done 
with it. That just delayed the ultimate slowdown. I haven't tried recently though so 
maybe JDK 1.3.1 has a fix for it. Still, I would advise using a different RDBMS. There 
are high quality free ones 
but if you don't mind paying I think Sybase ASA (not ASE which is the big one) for 
small to medium size projects is excellent.

On Fri, 3 Aug 2001 22:09:12 -0400, Jeffrey Worst wrote:

>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.






Re: Using Tomcat with MSAccess

2001-08-03 Thread Jeffrey Worst

I can't see any errors in the Tomcat DOS window so I'm assuming they have
scrolled off the screen.  The only error I see is the HTML generated by the
"else" clause if the insertIntoDB method doesn't run successfully.  I'm
running Win98 and the Access DB file access properties are only set to
Archive.

Jeff


- Original Message -
From: "Bojan Smojver" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, August 03, 2001 10:23 PM
Subject: Re: Using Tomcat with MSAccess


> What's the actual error message?
>
> Maybe you can print out the SQL statement to see if the syntax is OK. It
> could be invalid SQL. Are you running this under Windows NT/2000 or
> 9x/ME? Maybe the user Tomcat runs under doesn't have access rights on
> this database?
>
> I don't really use Access, I'm just trying to apply my PostgreSQL
> experiences...
>
> And maybe you can have a look at JBoss or similar EJB container. No more
> SQL...
>
> Bojan
>
> Jeffrey Worst wrote:
> >
> > 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
>




Re: Using Tomcat with MSAccess

2001-08-03 Thread Bojan Smojver

What's the actual error message?

Maybe you can print out the SQL statement to see if the syntax is OK. It
could be invalid SQL. Are you running this under Windows NT/2000 or
9x/ME? Maybe the user Tomcat runs under doesn't have access rights on
this database?

I don't really use Access, I'm just trying to apply my PostgreSQL
experiences...

And maybe you can have a look at JBoss or similar EJB container. No more
SQL...

Bojan

Jeffrey Worst wrote:
> 
> 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