> > I have a form from which I want to send text data to a
> database via a
> > servlet. The problem is: When there is single quote or double quote
> > somewhere in the to-be-input text, I get a JDBC,... error.
> I understand that
> > JDBC confuses with these quotes? How can I overcome this problem?
> >
>
> Most databases have some sort of an escape syntax that lets
> you embed single
> quotes. The problem is that they are not consistent in how
> they deal with it.
>
> To get around this in a DB-independent way, use a
> PreparedStatement instead:
>
> Connection conn = ...
> String name = "My name's got a single quote in it";
> double value = 3.14159;
> PreparedStatement stmt = conn.prepareStatement("insert
> into my_table
> (my_name, my_value) values (?, ?)");
> stmt.setString(1, name);
> stmt.setDouble(2, value);
> stmt.executeUpdate();
>
> This makes the JDBC driver take care of the embedded single
> quote, which it
> will do in whatever manner is appropriate for the database
> you are running on.
I don't think any JDBC drivers actually escape characters when you are using
a PreparedStatement. The parameters are actually placed using function calls
to the DB instead of replacing the question marks in the SQL statement.
PreparedStatements are much more flexible than normal Statements and I use
them for all but the simplest queries.
>
> >
> > Second, as using MsAccess I observed that I could a max of
> 256 characters
> > into a text type field? What should I do to increase this
> limit? Is there
> > another way to store text data in a database? Which type
> should I use?
> >
>
> I'm not a heavy duty Access user, but I imagine there is some
> sort of Memo
> field that can hold more characters than 256.
>
Memo is actually the name of the field type in Access. Good Guess! ;-)
Aaron
___________________________________________________________________________
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