JSP and MYsql database

The code below is what i have been using to try and get a connection along with some information with the database. The only problem that i can not get passed results = sql.executeQuery(); I have added println statement and i only get up to 3 which is before results = sql.executeQuery(); What is my mistake??

When i run the query, SELECT member_id FROM member WHERE user_name = + '" + name + "'" and hard code the name it does get back one number. So i don't know what the problem is!

Please correct the file below to show me where i have gone wrong..thank-you in advance



<html>
<head>
<%@ page
     import = "java.io.*"
     import = "java.lang.*"
     import = "java.sql.*"
%>
<title>
TEST
</title>
</head>
<body>
<%
     String     name;
     Connection dbconn;
     ResultSet results;
     PreparedStatement sql;
     try
     {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          try
          {
               int mem;
               boolean     doneheading = false;
               out.println("1");
               out.println();
               dbconn = DriverManager.getConnection("jdbc:mysql://localhost/nutrition","saundersk","kevin");
         
               out.println("2");
               name = request.getParameter("name");
               sql = dbconn.prepareStatement("SELECT member_id FROM member WHERE user_name = + '" + name + "'");
               out.println("3");
         
               results = sql.executeQuery();
               
               out.println("4");
               while(results.next())
               {
                    out.println("5");
                    if(! doneheading)
                    {
                         out.println("6");
                         out.println("<table border=2>");
                         doneheading = true;
                         
                    }
                                out.println("7");
                                mem = results.getInt("member_id");
                    out.println("<tr><td>" + mem);
         

               }
               if(doneheading)
               {
                    out.println("8");
                    out.println("</table>");
               }
               else
               {
                    out.println("9");
                    out.println("No matches for ");
               }
          }          
          catch (SQLException s)
          {
               out.println("SQL Error<br>");
          }
     }
     catch (ClassNotFoundException err)
     {
          out.println("Class loading error");
        }
%>
</body>
</html>
KTSAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sfotexCommented:
try:
              sql = dbconn.prepareStatement("SELECT member_id FROM member WHERE user_name =  ? + ");


sql.setString(1, request.getParameter("name"));
results = sql.executeQuery();

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
objectsCommented:
> member WHERE user_name = +

Get rid of that '+'
0
KTSAuthor Commented:
What does sql.setString(1, request.getParameter("name")); this do?


if i wanted to change my SELECT STATEMENT TO..."SELECT * FROM member WHERE UPPER(user_name) = ?"

how would i change the rest of the code to get all the fields output..there are five fields....username, password1, password2, memeber_id, email_add
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

objectsCommented:
Did u try just getting rid of the '+'?

> What does sql.setString(1, request.getParameter("name")); this do?

It fills in the value of the 1st placeholder ?

> how would i change the rest of the code to get all the fields output..

Use result.getObject(fieldname) to retrieve the column values from the rs.

0
KTSAuthor Commented:
What does sql.setString(1, request.getParameter("name")); this do?


if i wanted to change my SELECT STATEMENT TO..."SELECT * FROM member WHERE UPPER(user_name) = ?"

how would i change the rest of the code to get all the fields output..there are five fields....username, password1, password2, memeber_id, email_add
0
KTSAuthor Commented:
What does sql.setString(1, request.getParameter("name")); this do?


if i wanted to change my SELECT STATEMENT TO..."SELECT * FROM member WHERE UPPER(user_name) = ?"

how would i change the rest of the code to get all the fields output..there are five fields....username, password1, password2, memeber_id, email_add
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.