File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL syntax error

 
Robbie kyodo
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Dana Hanna
Ranch Hand
Posts: 227
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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());
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic