Hello All,

I am trying to insert two values into a access database from a Servlet. The 
values are form variables consisting of  a URL and a name. I'm  getting the 
following error:

SQL Exception Caught: [Microsoft][ODBC Microsoft Access Driver] Syntax error 
in INSERT INTO statement.  

If anyone can help with this I appreciate it very much.  I have attached the 
Servlet source code.

Thanks,
Brian  
package  com.wrox.projsp.ch03.myfirstwebapp;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;

public class AddLink extends HttpServlet {

  public void init(ServletConfig config) throws ServletException {
    super.init(config);
  }

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws 
ServletException, IOException {

      response.setContentType("text/html");

      PrintWriter out = response.getWriter();
      Connection con = null;
      Statement stmt = null;
      ResultSet rs = null;
      String error = null;
      String url = request.getParameter("url");
      String favName = request.getParameter("favName");
      int count=0;
      String tmp = null;

    try {

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
    con = DriverManager.getConnection("jdbc:odbc:LINKS","","");
    stmt = con.createStatement();
    tmp = "insert into LINKS(VALUE, NAVIGATION_TEXT) values('"+url+"','"+favName+"')";
    count = stmt.executeUpdate(tmp);

     out.println("Favorite Link Added with Success!");



    }

    catch (ClassNotFoundException e) {
    error = "Could not load database driver: " + e.getMessage();
    out.println(error);
    }

    catch (SQLException e) {
    error = "SQL Exception Caught: " + e.getMessage();
    out.println(error);
    }

    finally {
      try {

        if (con != null) con.close();

        }
        catch (SQLException ignored) {}
        }
    }





}



Reply via email to