473,418 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

How to retrieve value from database

Can any one tell me how to retrieve values from database? i got the column names of the table but i don't know how to get the particular value from data base
this is my code
submit.jsp:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <body>
  3.         <form action="EmpDeligator" method="get">
  4.             <input type="text" name="empid"/>
  5.             <input type="SUBMIT" name="submit"/>
  6.  
  7.         </form>
  8.     </body>
  9. </html>
  10.  
  11. EmpDeligator.java
  12.  
  13.  * To change this template, choose Tools | Templates
  14.  * and open the template in the editor.
  15.  */
  16.  
  17.  
  18. import DataBase.EmpDetails;
  19. import java.io.IOException;
  20. import java.io.PrintWriter;
  21. import java.sql.ResultSet;
  22. import java.sql.ResultSetMetaData;
  23. import java.sql.SQLException;
  24. import javax.servlet.RequestDispatcher;
  25. import javax.servlet.ServletContext;
  26. import javax.servlet.ServletException;
  27. import javax.servlet.http.HttpServlet;
  28. import javax.servlet.http.HttpServletRequest;
  29. import javax.servlet.http.HttpServletResponse;
  30.  
  31. /**
  32.  *
  33.  * 
  34.  */
  35. public class EmpDeligator extends HttpServlet {
  36.  
  37.     /** 
  38.      * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  39.      * @param request servlet request
  40.      * @param response servlet response
  41.      * @throws ServletException if a servlet-specific error occurs
  42.      * @throws IOException if an I/O error occurs
  43.      */
  44.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  45.     throws ServletException, IOException {
  46.         response.setContentType("text/html;charset=UTF-8");
  47.         PrintWriter out = response.getWriter();
  48.        int colcount = 0;
  49.  
  50.              String ss = request.getParameter("empid");
  51.              ResultSet rs = EmpDetails.gettingString(ss);
  52.                     try{
  53.    ResultSetMetaData  rsmd = rs.getMetaData();
  54.    colcount = rsmd.getColumnCount();
  55.  
  56.    out.println("<table border = 1>");
  57.  
  58.    for(int iu = 0; iu<colcount; iu++){
  59.        out.println("<td>"+rsmd.getColumnName(iu+1));
  60.         }out.println("<tr>");
  61.     }catch(Exception e){}
  62.  
  63.               for(int iu = 0; iu<colcount; iu++){
  64.             try {
  65.                 out.println("<td>" + rs.getString(iu + 1));
  66.                 out.println("<tr>");
  67.             } catch (SQLException ex) {
  68.                 ex.printStackTrace();
  69.             }
  70.  
  71.               }
  72.  
  73. EmpDetails.java
  74. /*
  75.  * To change this template, choose Tools | Templates
  76.  * and open the template in the editor.
  77.  */
  78.  
  79. package DataBase;
  80. import java.sql.*;
  81. /**
  82.  *
  83.  * @author harikrishna
  84.  */
  85. public class EmpDetails
  86. {
  87.     public static ResultSet gettingString(String str)
  88.      {
  89.         int txtempno;
  90.          String sqlstr;
  91.          ResultSet rs=null;
  92.          try
  93.         {
  94.          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  95.          Connection con=DriverManager.getConnection("jdbc:odbc:demo","sysman","ajaykumar");
  96.          Statement stmt=con.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  97.          sqlstr="select * from employee_log where empid = "+str;
  98.  
  99.                 rs=stmt.executeQuery(sqlstr);
  100.  
  101.  
  102.         }catch(Exception se)
  103.         {
  104.             se.printStackTrace();
  105.         }
  106.  
  107.          return rs;
  108.      }
  109.  
  110.  
  111. }
  112. Table.jsp
  113. <%-- 
  114.     Document   : Table
  115.     Created on : May 29, 2010, 11:15:22 AM
  116.     Author     : harikrishna
  117. --%>
  118. <%@page import="java.sql.*;" %>
  119. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  120. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  121.    "http://www.w3.org/TR/html4/loose.dtd">
  122.  
  123. <html>
  124.    <table>
  125.    <%
  126.    ResultSet rs=(ResultSet) session.getAttribute("rs");
  127.    ResultSetMetaData  rsmd = rs.getMetaData();
  128.    int colcount = rsmd.getColumnCount();
  129.  
  130.    for(int iu = 0; iu< colcount;iu++)
  131.        {%>
  132.  
  133. <td><%=rsmd.getColumnName(iu)%>
  134.  
  135. <%
  136. }out.println("<tr>");
  137. %>
  138.  
  139.  
  140. <table>
  141. </html>
In the "Table.jsp" i got the code for getting the column but i dnt know how to get the particular value into jsp

please help me friends i have struc here.....
Jun 1 '10 #1
0 1330

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Salvani Langosta | last post by:
In an Access 97 database, I use serveral global variables that hold information about the database, for example: gstrFileServer - holds the server root where the database is stored...
12
by: Dica | last post by:
i can't seem to find a way to cast the value in my comboBox to integer. i've tried the following: short iProjectID = Convert.ToInt16(cboProjects.SelectedValue); i keep getting a "Sepcified...
2
by: rajrajnew | last post by:
Hi, I developed web usercontrol, which populates all countries data. I want to retrieve value from it and place it on a label with out using button click event. I mean that it should act like...
5
by: fruityfreak | last post by:
I would like to know how to I retrieve information from another database table... Instead of keying in manually, I would like to retrieve data directly from the logged in user row. For the user...
2
by: priyanka1915 | last post by:
helloo, I have to retrive the data from database and then check that value my column in database is CATEGORY ------------------------------- COMMODITY COMMODITY COMMODITY
1
ganeshkumar08
by: ganeshkumar08 | last post by:
Hi all, Can i know how to retrieve the database which is deleted without knowing. I deleted one database, now i dont know how to retrieve it.. Can any one help me.. Thanks Ganesh
2
by: Cramer | last post by:
Using ASP.NET 3.5... As far as I know, any time we store a value in application or session state, it is stored as a humble 'object' type rather than it's "real" type. For example, if we want...
4
by: Michael | last post by:
I am using Web Developer Express 2005. I created a little form to add some content to a database. I keep the formview default mode in the insert mode. The values are being added to the database...
3
crystal2005
by: crystal2005 | last post by:
Hi all, As the title, how do i retrieve a value from the URL format string after i pass it to the other page. E.g. example in my case is Say in admin.aspx i have a link to questions.aspx. I...
7
by: shalskedar | last post by:
In a query i want to retrieve the value in such a way that if the value for the current record for a given column is 0 then it should go to the next record & take the value. for ex-I 've column...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.