Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

search  RSS feed

 
Sri Gnana
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any one give me the code samples for search the database and get data for updation in jsp
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Sun Microsystems can. You want to read the JSP and JDBC tutorials you will find there.
 
Arvind Kini
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks a lot
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!