Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package searchbook;
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.sql.*;
- import java.util.*;
- public class SearchBook extends HttpServlet {
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException,IOException{
- response.setContentType("text/html");
- HttpSession session = request.getSession(true);
- List booklist=new ArrayList();
- Connection con = null;
- String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + "C:\users\ppreeti\executive_db.accdb";
- String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
- String user = "";
- String pass = "";
- String category="";
- category=request.getParameter("input");
- String sqlquery="select Index1.link_id "
- + "FROM Index1 "
- + " WHERE Index1.index_name LIKE '%"+category+"%' ";
- try
- {
- Class.forName(driver);
- con = DriverManager.getConnection(url, user, pass);
- try{
- Statement st = con.createStatement();
- System.out.println("Connection created");
- ResultSet rs = st.executeQuery(sqlquery);
- System.out.println("Result retreived ");
- }
- catch (SQLException s)
- {
- System.out.println("SQL statement is not executed! "+ s);
- }
- }
- catch (Exception e){
- e.printStackTrace();
- }
- if(sqlquery.equals("1"))
- {
- String sqlq="select Section.Section_Name , Report.Report_Name , Report.Link, Contact.Contact_Name, Metrics.Metric_Name "
- + "FROM Section , Report , Contact,Metrics "
- + "WHERE Report.Contact_ID=Contact.Contact_ID and Report.Section_ID=Section.Section_ID "
- + "and Report.Report_ID IN (SELECT Metrics.Report_ID FROM Metrics WHERE Metrics.Metric_Name = Report.Report_ID') and Metrics.Metric_Segment = 'M' ";
- }
- try
- {
- Class.forName(driver);
- con = DriverManager.getConnection(url, user, pass);
- try
- {
- Statement st = con.createStatement();
- System.out.println("Connection created");
- ResultSet rs = st.executeQuery(sqlq);
- System.out.println("Result retreived ");
- while (rs.next())
- {
- List<String> book=new ArrayList<String>();
- String Name=rs.getString("Section_Name");
- String reportName=rs.getString("Report_Name");
- String link=rs.getString("Link");
- String contactName=rs.getString("Contact_Name");
- String metricName=rs.getString("Metric_Name");
- //String reportId=rs.getString("Report_ID");
- /*String ind_id=rs.getString("index_name");
- String ind_name=rs.getString("link_id");*/
- book.add(Name);
- book.add(reportName);
- book.add(link);
- book.add(contactName);
- book.add(metricName);
- //book.add(reportId);
- /*book.add(ind_id);
- book.add(ind_name);*/
- booklist.add(book);
- }
- }
- catch (SQLException s)
- {
- System.out.println("SQL statement is not executed! "+ s);
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- request.setAttribute("booklist",booklist);
- RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/searchbook.jsp");
- dispatcher.forward(request, response);
- }
- }
- if(sqlquery.equals("1"))
- {
- String sqlq="select Section.Section_Name , Report.Report_Name , Report.Link, Contact.Contact_Name, Metrics.Metric_Name "
- + "FROM Section , Report , Contact,Metrics "
- + "WHERE Report.Contact_ID=Contact.Contact_ID and Report.Section_ID=Section.Section_ID "
- + "and Report.Report_ID IN (SELECT Metrics.Report_ID FROM Metrics WHERE Metrics.Metric_Name = Report.Report_ID') and Metrics.Metric_Segment = 'M' ";
- // Note the try is now nested under the if
- try
- {
- // code continues here
- String sqlq = "";
- if (...) {
- sqlq = ...;
- }
- if(sqlquery.equals("1"))
- {
- String sqlq
- }
Add Comment
Please, Sign In to add comment