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;



connection = DriverManager.getConnection(connectionURL, "NAMEUSER", "PASS");
statement = connection.createStatement();
rs = statement.executeQuery(sql);

while (rs.next()) {



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?! :-(


The solution is do not do database connectivity from inside a JSP. Check this thread to see how to go about this the right way.

Wow.. and where please? Is somewhere some examples, some tutorials... something please?

This article has been dead for over six months. Start a new discussion instead.