• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

SQL syntax error

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have a servlet which supposed to update my Access table. My table contains 3 fields :
account,password,name.
I ran below snippets of my servlet and compiler gave me SQL syntax error.
String INSERT ="INSERT INTO login-table (login_id ,password ,name) " + "VALUES (?, ?, ?)";
PreparedStatement pstmt = null;
pstmt = con.prepareStatement(INSERT);
pstmt.setString(1, account);
pstmt.setString(2,password);
pstmt.setString(3,name);

I also tried this SQL format .
stmt.executeUpdate("INSERT INTO login-table " + " (login_id ,password ,name ) " + "VALUES " + "('" + account + "', '" + password + "', '" + name + "');");
Also gave me SQL syntax error
Pls help
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you paste the exact SQLException tht you get when executing the first statement?
On what line does the error occur?
What driver are you using / could you paste entire servlet?
 
Robbie kyodo
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tested the JDBC-ODBC connection, its working fine , its just the SQL command....(i thk)
2003-06-17 10:47:48 - PoolTcpConnector: Starting Ajp12ConnectionHandler on 8007
SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT I
NTO statement.

import java.sql.*;

public class RegisterHandler extends HttpServlet {

public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException {
String url = "jdbc dbc:login";
Connection con;
String compareString;
String name = req.getParameter("name");
String account = req.getParameter("account");
String password = req.getParameter("password");
compareString = "SELECT login_id FROM login-table" +
" WHERE login_id == account)";

PrintWriter out = res.getWriter();
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();
String INSERT =
"INSERT INTO login-table (login_id ,password ,name) " +
"VALUES (?, ?, ?)";
PreparedStatement pstmt = null;
pstmt = con.prepareStatement(INSERT);
pstmt.setString(1, account);
pstmt.setString(2,password);
pstmt.setString(3,name);
pstmt.executeUpdate();
out.println("<HTML><HEAD><BODY>Successfully Created</BODY></HEAD></HTML>");
//}

stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic