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


Recommended Answers

All 4 Replies

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?

Here you go.

Thanks A lot for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.