Hi,
I am writing a servlet using NetBeans that finds scores from a mySQL database. I have a simple select using a prepared statement. But I get the following error.
INFO: com.mysql.jdbc.exceptions.MySQLSyntaxErrorExceptio n: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''csci1301'' at line 1
I don't see what is wrong.
response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String ssn; String tableName; String studentName=""; int score = 0; try { /* * TODO output your page here. You may use following sample code. */ out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Exercise39_7</title>"); out.println("</head>"); out.println("<body>"); ssn = request.getParameter("ssn"); tableName = request.getParameter("course"); String queryString = "select * from ? "; pstmt = conn.prepareStatement(queryString); pstmt.setString(1, tableName); ResultSet rset = pstmt.executeQuery(); while (rset.next()) { if (rset.getString("ssn").equals(ssn)){ out.println(rset.getString(studentName) + " " + rset.getInt(score)); } }
Any help would be appreciated.