Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

search

 
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can any one give me the code samples for search the database and get data for updation in jsp
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. Sun Microsystems can. You want to read the JSP and JDBC tutorials you will find there.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The following code is used to search a particular details from database(here database i used is Ms-access). the following code is in servlet.. convert into jsp.. that is quite easy....

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Search extends HttpServlet
{

public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;

res.setContentType("text/html");
PrintWriter out=res.getWriter();
String ename = req.getParameter("Emp_no");
int Emp_no = (new Integer(req.getParameter("Emp_no"))).intValue();
out.println(ename);
//String y = ename;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc dbc:EMP","","");
stmt = conn.createStatement();
rs =stmt.executeQuery("select * from Emp where Empno = '" + Emp_no + "'");

out.println("<html><body ><center>");
out.println("<table border=2 width=60% bgcolor=silver>");
out.println("<tr><th width=30%>Employee Name</th><th width=15%>EmpNo</th><th width=15%>Age</th><tr>");

while(rs.next())
{
out.println("<tr><td>" +rs.getString("Name") +"</td><td>"+rs.getString("Empno")+"</td><td>"+rs.getString("Age")+"</td>");
}

out.println("<A HREF=\"/examples/jsp/Menu.jsp\">Go To MainMenu..</A>");
out.println("</table></center></body></html>");
}
catch(ClassNotFoundException e){}
catch(SQLException e){out.println(e);}
finally
{
try
{
if(conn!=null)
conn.close();
}
catch(SQLException ignored){}
}
}
}


Bye!
 
Sri Gnana
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic