aspose file tools*
The moose likes Servlets and the fly likes SQL syntax error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "SQL syntax error" Watch "SQL syntax error" New topic
Author

SQL syntax error

Robbie kyodo
Ranch Hand

Joined: May 05, 2003
Posts: 97
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


SCJP 2 1.4
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
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

Joined: May 05, 2003
Posts: 97
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
 
subject: SQL syntax error