Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Retrieve data from databse using where in JSP

Have Programming Question? Ask it here!
 
 
 


Arjun Sasi
Retrieve data from databse using where in JSP
1 Answer(s)      a year and 2 months ago
Posted in : JSP-Servlet


Hi, can somebody help me?

I have a jsp page. in that i want to get data from the database where username is matched. i tried it. but can't get the output. here is the code. please help me. ALL DATABASE CONNECTIONS ARE OK. THE ERROR IS SHOWN IN "WHERE". IT SAYS INCORRECT SQL SYNTAX

<html>
   .....
<body>
 <%
      //table name is "register" have Name and Username filed.
      String uname=request.getParameter("username");
      String sql;
      sql="SELECT * FROM register WHERE Username="+uname+"";
      ResultSet rs=stmt.executeQuery(sql);
      while(rs.next())
                    {
      %>          

   NAME: <%=rs.getString(1)%> 
   USERNAME: <%=rs.getString(2)%> 

       <%        
                }
         %> 

   </body>
</html>

Advertisement
View Answers

February 6, 2013 at 4:26 PM


hi friend,

I think in your sql query you missed the single quote ( ' ) after Username. This is required because you are searching for a text and text should be written within the single quote such as in your example your query should be written as follows :

SELECT * FROM register WHERE Username='"+uname+"'"

you may try the following code :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*;" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Delete Data</title>
</head>
<body>
<form action="#">
<table>
<tr>
<td>Enter Username</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Register"/></td>
</tr>
</table>
</form>
<%! String driverName = "com.mysql.jdbc.Driver";%>
<%! String url = "jdbc:mysql://localhost:3306/record";%>
<%! String user = "root";%>
<%! String psw = "root";%>
<%
String uname = request.getParameter("username");
if(uname != null)
{
Connection con = null;
PreparedStatement ps = null;    
try
{
    Class.forName(driverName);
    con = DriverManager.getConnection(url,user,psw);
    String sql = "SELECT * FROM register WHERE Username='"+uname+"'";
    ps = con.prepareStatement(sql);
    ResultSet rs = ps.executeQuery();
    while(rs.next())
    {
        %>
        Name = <%=rs.getString("Name") %>
        <%

    }
}   
catch(SQLException sqe)
{   
    out.println(sqe);
}
}
%>
</body>
</html>


Related Tutorials/Questions & Answers:
Retrieve data from databse using where in JSP
Retrieve data from databse using where in JSP  Hi, can somebody help me? I have a jsp page. in that i want to get data from the database where...=request.getParameter("username"); String sql; sql="SELECT * FROM register WHERE
how to print data(From databse Oracle10g) in preformatted A4 and A3 paper using jsp
how to print data(From databse Oracle10g) in preformatted A4 and A3 paper using jsp  how to print data(From databse Oracle10g) in preformatted A4 and A3 paper using jsp. I am inserting analysis report into a database using
Advertisements
retrieve related data from database using jsp and mysql
retrieve related data from database using jsp and mysql  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list. if we change a value in a dropdown its related value must
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ...).second .java file for getting data from second table- package pack; public... for retrieving data fromm two tables : first table having fields: bookid,name
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ...).second .java file for getting data from second table- package pack; public... for retrieving data fromm two tables : first table having fields: bookid,name
how to retrieve data from multiple tables in jsp using javabeans
how to retrieve data from multiple tables in jsp using javabeans   ...).second .java file for getting data from second table- package pack; public... for retrieving data fromm two tables : first table having fields: bookid,name
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrieve data from database using combobox value without using request.getParameter in jsp  Answer pl
Read Excel data using JSP and update MySQL databse
Read Excel data using JSP and update MySQL databse  HOw to read excel data using JSP and update MySQl database
How to Retrieve Data from Facebook Using PHP
How to Retrieve Data from Facebook Using PHP  is this link has right content regards that?? http://techpdf.co.cc/blog/how-to-retrieve-data-from-facebook-using-php
How to Retrieve Data from Facebook Using PHP
How to Retrieve Data from Facebook Using PHP  is this link has right content regards that?? http://techpdf.co.cc/blog/how-to-retrieve-data-from-facebook-using-php
retrieve data from database using jsf
retrieve data from database using jsf  Hello I want an example of source code to retrieve data from database i have a database (oracle) name as db1...),, name ,and city I want after enter value in textbox according idauthor i retrieve
Retrieve data from xml using servlets
Retrieve data from xml using servlets  Hi plz send me the code for retrieving the data from xml File using Servlets.   Hi, Do you want... Thanks   Hi, Learn Get Data From the XML File. Thanks
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
How to retrieve data from database by using combo box value in jsp?  Hello friend i want use only one jsp page.. but u give 2 pages... I want to work in one page... Pl response.. I do not need getParameter... Pl respose me
how to insert data from netbeans into databse
how to insert data from netbeans into databse  how to insert data from netbeans into databse   Please visit the following link: http://www.roseindia.net/webservices/web-services-database.shtml
How to Retrieve Data from the database and write into excel file using Java
How to Retrieve Data from the database and write into excel file using Java  Hi, I am trying to develop an small application where i trying to retrieve Data from the database and store the details in excel file. Please can
Retrive data from databse to a text field - Java Server Faces Questions
Retrive data from databse to a text field  Hi, Can you give me a source code to rertrve data from Mysql databse to a text field using JSF.....by selecting option from a dropdown option
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  I am using a single jsp form.. i did not get from another form.. i do not use 2 jsp form.. all.... Note: I am using only this jsp form.. i do not use
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  For example, In Employee.jsp form, When i click employee id value in combo box...... i already stored combo box values from database. pl
how to retrieve data from database
how to retrieve data from database  unable to retrieve data from database using mySQL by using jsp sessions and beans for editing
<img src=""> using retrieve image from database using jsp
using retrieve image from database using jsp  how to <img src="" > tag using retrieve image from database and display in jsp
How to retrieve data using combo box value in jsp? - JSP-Servlet
How to retrieve data using combo box value in jsp?  Hi freind, I already post this question. I need urgent help from u. pl response me... the following link: http://www.roseindia.net/jsp/comboSelect.shtml Hope
insert data into mysql databse using swing
insert data into mysql databse using swing   Blockquote hi, here is my code, i want code for store data into mysql database when click on submit button from access data from this form, please provide code, import java.awt.
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve data by using combo box value in jsp?  Hi Friends... related value.... I am using only this page.. not get value from another page... in combo box from database.. by using select*from studentinformation; But when i
how to create a bar chart in jsp by fetching value from oracle databse?
how to create a bar chart in jsp by fetching value from oracle databse?  i want to show the population of various states in a bar chart in my jsp page by fetching the data from my oracle table. i am using my eclipse as my IDE
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
how to retrieve data from database ?????/
how to retrieve data from database ?????/  how to retrieve data from database
Retrieve The Data From MySql Datbase
Retrieve The Data From MySql Datbase   How to Retrieve The Data From MYSQL database TO Use Select the Emp_id Option.And Also Search Option
ID using get the databse latest value and displayed in jsp
", "root"); //String query = "select * from Data where id='"+no+"'"; Statement st...ID using get the databse latest value and displayed in jsp  function...; <% } } catch(Exception e){} %> I have done jsp page like this .... I
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql... * from testtable where Fname like '%$term%'"); while ($row = mysql<em>
Retrieve data from database by using sql tag of JSTL SQL library
Retrieve data from database by using sql tag of JSTL SQL library... we will see how retrieve data from database using sql query given by user. To execute query first create a data source and then execute sql query
retrive article from sql databse and show using php
retrive article from sql databse and show using php  hello sir i have sql database which i store articles.i want to show these article on web page using php. my field are image,title,summary,content id. plz provide me
retrieve data from database with hyperlink
retrieve data from database with hyperlink  sir....i have one table called 'name' having two values i have to retrieve those data with a hyperlink... have values C C++ i have to retrieve and if i click C its sub categories should
Data retrieve from mysql database
Data retrieve from mysql database  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list... from the dropdown, related data will get displayed on the textboxes. Here we have
ID using get the databse latest value and displayed in jsp
ID using get the databse latest value and displayed in jsp   I have... ... once click the submit button the data will be stored in mysql database... in the form (it means latest values) ... how to retrive that values using ID
How to insert data into databse by JSP form registration page in netbeans
How to insert data into databse by JSP form registration page in netbeans  ... of data for login purpose. I have created 1 form in JSP netbeans with both username.... & how to connect tht form to my databse , so it can store data?   1
How to Retrieve data from database in jsp
How to Retrieve data from database in jsp In this section we will discuss... are going to discus about retrieve data from database in jsp.First of all we have...;font><strong>Retrieve data from database in jsp</strong><
Exporting data from mysql into csv using jsp
Exporting data from mysql into csv using jsp  Hi friends.... I want to export the data from mysql to csv file using... i am having 30 columns in my database.. Eg- text1,text2,text3,....,upto text30... i want to export this data
how insert data from databse in array and compare new data to already stored value in array
how insert data from databse in array and compare new data to already stored value in array   hello all i tried to fetch data from databse and try to stored it in an array and i want to compare new value that come from database
Retrieve data using Criteria api
Retrieve data using Criteria api  import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Query; import org.hibernate.Criteria; import org.hibernate.criterion.Restrictions; import
retrive data from database using jsp in struts?
retrive data from database using jsp in struts?   *search.jsp* <... searchProduct(SearchDTO sdto) { String query="select * from product"; if(sdto.getPid()==null || !sdto.getPid().equals("")) { query=query+" "+"where pid
how to use bean to retrieve data from database
how to use bean to retrieve data from database  how to use bean to retrieve data from database   poda sendru
how to insert, retrieve data from,to db(code)....
that data will b stored in db(m using sybase). 2.also hw to retrieve the data from...how to insert, retrieve data from,to db(code)....  Hi..... i ve.../javascriptpagerefresh.shtml http://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons ...),avdRed(float),avgGreen(float),avgBlue(float) i have to retrieve all the fields of various rows from database in labels by clicking previous and next
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons ...),avdRed(float),avgGreen(float),avgBlue(float) i have to retrieve all the fields of various rows from database in labels by clicking previous and next
Retrieving data from data base using jsp combo box
Retrieving data from data base using jsp combo box  Hi guys please help me , i have on GUI page int that Server type(like apache,jboss,weblogic) one... of the server it has to display the process name from database into the process name
how to insert, retrieve data from,to db(code)....
will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u...how to insert, retrieve data from,to db(code)....  Hi, i have created...://www.roseindia.net/jsp/user-registration-form-using-jsp.shtml
JSP and XML .data store nd retrieve
in xml file.How can i store data entered by user in XML file and later retrieve data in another jsp page using retrieve submit button.Please tell step by step...JSP and XML .data store nd retrieve  I have made a form in jsp having
Retrieve values from database using views
Retrieve values from database using views  hi......... I have a huge... the columns which are required. As my front end is java swings i want to retrieve data... giving me error . So can u plz help??????? Can u tell me how to retrieve data
Advertisements
 

 

 

DMCA.com