// Needs a connection so it can fetch more stuff lazily Copy(ResultSet rs) throws SQLException { super(); copyId = rs.getInt("copy#"); bibId = rs.getInt("bib#"); note = rs.getString("pac_note"); location = rs.getString("location"); locationName = rs.getString("location_name"); collectionDescr = rs.getString("collection_descr"); collection = rs.getString("collection"); callNumber = new CallNumber( rs.getString("call_number"), rs.getString("call_type"), rs.getString("copy_number"), rs.getString("call_type_hint")); callType = rs.getString("call_type"); callTypeHint = rs.getString("call_type_hint"); callTypeName = rs.getString("call_type_name"); mediaType = rs.getString("media_type"); mediaTypeDescr = rs.getString("media_descr"); summaryOfHoldings = rs.getBoolean("summary_of_holdings"); itemType = rs.getString("itype"); itemTypeDescr = rs.getString("idescr"); }
public static void main(String[] args) throws SQLException, ClassNotFoundException, JSONException { PostgresDb db = new PostgresDb(); // db.setUrl("jdbc:postgresql://localhost:5432/powaaim"); try { Class.forName("org.postgresql.Driver"); c = DriverManager.getConnection(db.getUrl(), db.getUser(), db.getPass()); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } st = c.createStatement(); rs = st.executeQuery("SELECT id, name, externalshopid from shop where name='David_3'"); System.out.println("id" + " " + "name" + " " + "externalshopid"); c.close(); obj = new JSONObject(); while (rs.next()) { int id = rs.getInt("id"); String externaId = rs.getString("externalshopid"); String name = rs.getString("name"); // System.out.println(id+ " " + " "+ name + " " +" "+ externaId); System.out.println(); obj.put("id", id); obj.put("name", name); obj.put("externalshopid", externaId); System.out.print(obj); } }
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { /* * TODO output your page here out.println("<html>"); * out.println("<head>"); out.println("<title>Servlet * JDBCServlet</title>"); out.println("</head>"); * out.println("<body>"); out.println("<h1>Servlet JDBCServlet at " + * request.getContextPath () + "</h1>"); out.println("</body>"); * out.println("</html>"); */ prefixHTML(out); DAO dao = new DAO(); dao.connect(); ResultSet rst = dao.getAll(); if (rst != null) { while (rst.next()) { int id = rst.getInt(1); String foo = rst.getString(2); String bar = rst.getString(3); out.println(foo + ", " + bar + "<br/>"); } } else { out.println("failed to get data from database <br/>"); } out.println("Getting capital of India <br/>"); rst = dao.getCapital("India"); if (rst != null) { while (rst.next()) { String foo = rst.getString("CAPITAL"); out.println(foo + "<br/>"); } } else { out.println("failed to get capital for India"); } dao.disconnect(); } catch (Exception e) { e.printStackTrace(); } finally { postfixHTML(out); out.close(); } }