Hi all, i'm newbie with jsp and i'm trying to connect with mysql through a select with a variable passed from an another page...
The code i have is what follows:
<%
// Prendo la variabile dal form
String username=request.getParameter("username");
String sql="SELECT * FROM cmascella_users WHERE username = " + username + " ";
String connectionURL = "jdbc:mysql://localhost/NAMETABLE?user=NAMEUSER&password=PASS";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
//out.write(sql);
%>
<html><body>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "NAMEUSER", "PASS");
statement = connection.createStatement();
rs = statement.executeQuery(sql);
while (rs.next()) {
out.println(rs.getString("username")+"<br>");
}
rs.close();
%>
The problem is that i get back an error ...this one:
javax.servlet.ServletException: Unknown column 'Trottolone' in 'where clause'
...it's seem the sql is trying to look for a column named "Trottolone" that is the username!!! What wrong?! :-(
Thanks