0

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

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by sawedd
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.