-
-
Save narektutikian/62a035dd627e98803a40 to your computer and use it in GitHub Desktop.
ebookshop |
<component name="ArtifactManager"> | |
<artifact type="exploded-war" name="ebookshop:war exploded"> | |
<output-path>$PROJECT_DIR$/out/artifacts/ebookshop_war_exploded.war</output-path> | |
<root id="root"> | |
<element id="javaee-facet-resources" facet="ebookshop/web/Web" /> | |
<element id="directory" name="WEB-INF"> | |
<element id="directory" name="classes"> | |
<element id="module-output" name="ebookshop" /> | |
</element> | |
<element id="directory" name="lib"> | |
<element id="library" level="project" name="taglibs-standard-compat-1.2.5" /> | |
<element id="library" level="project" name="taglibs-standard-jstlel-1.2.5" /> | |
<element id="library" level="project" name="standard" /> | |
<element id="library" level="project" name="jstl" /> | |
<element id="library" level="project" name="mysql-connector-java-5.1.37-bin" /> | |
</element> | |
</element> | |
</root> | |
</artifact> | |
</component> |
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="CompilerConfiguration"> | |
<resourceExtensions /> | |
<wildcardResourcePatterns> | |
<entry name="!?*.java" /> | |
<entry name="!?*.form" /> | |
<entry name="!?*.class" /> | |
<entry name="!?*.groovy" /> | |
<entry name="!?*.scala" /> | |
<entry name="!?*.flex" /> | |
<entry name="!?*.kt" /> | |
<entry name="!?*.clj" /> | |
<entry name="!?*.aj" /> | |
</wildcardResourcePatterns> | |
<annotationProcessing> | |
<profile default="true" name="Default" enabled="false"> | |
<processorPath useClasspath="true" /> | |
</profile> | |
</annotationProcessing> | |
</component> | |
</project> |
<component name="CopyrightManager"> | |
<settings default="" /> | |
</component> |
<?xml version="1.0" encoding="UTF-8"?> | |
<component name="dataSourceStorage"> | |
<data-source name="MySQL - ebookshop@localhost" uuid="4356f000-efc9-403b-b76f-a23fcd0ebac7"> | |
<database-info product="MySQL" version="5.5.5-10.1.8-MariaDB" jdbc-version="4.0" driver-name="MySQL Connector Java" driver-version="mysql-connector-java-5.1.35 ( Revision: 5fb9c5849535c13917c2cf9baaece6ef9693ef27 )"> | |
<extra-name-characters>#@</extra-name-characters> | |
<identifier-quote-string>`</identifier-quote-string> | |
</database-info> | |
<case-sensitivity plain-identifiers="lower" quoted-identifiers="lower"/> | |
<schema name="" catalog="ebookshop"/> | |
<table name="books" schema="" catalog="ebookshop" type="TABLE"> | |
<column name="id" sqlType="INT" precision="10" scale="0" nullable="false" jdbcType="4" autoIncrement="true"/> | |
<column name="title" sqlType="VARCHAR" precision="50" scale="0" nullable="true" jdbcType="12"/> | |
<column name="author" sqlType="VARCHAR" precision="50" scale="0" nullable="true" jdbcType="12"/> | |
<column name="price" sqlType="FLOAT" precision="12" scale="0" nullable="true" jdbcType="7"/> | |
<column name="qty" sqlType="INT" precision="10" scale="0" nullable="true" jdbcType="4"/> | |
<column name="category" sqlType="VARCHAR" precision="100" scale="0" nullable="false" jdbcType="12"/> | |
<column name="image" sqlType="VARCHAR" precision="100" scale="0" nullable="false" jdbcType="12"/> | |
<primary-key name="PRIMARY" columns="id"/> | |
</table> | |
</data-source> | |
</component> |
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="DataSourceManagerImpl" format="xml" hash="2015608271"> | |
<data-source source="LOCAL" name="MySQL - ebookshop@localhost" uuid="4356f000-efc9-403b-b76f-a23fcd0ebac7"> | |
<driver-ref>mysql</driver-ref> | |
<synchronize>true</synchronize> | |
<jdbc-driver>com.mysql.jdbc.Driver</jdbc-driver> | |
<jdbc-url>jdbc:mysql://localhost:3306/ebookshop</jdbc-url> | |
<driver-properties> | |
<property name="zeroDateTimeBehavior" value="convertToNull" /> | |
<property name="tinyInt1isBit" value="false" /> | |
<property name="characterEncoding" value="utf8" /> | |
<property name="characterSetResults" value="utf8" /> | |
<property name="yearIsDateType" value="false" /> | |
</driver-properties> | |
<libraries /> | |
</data-source> | |
</component> | |
</project> |
<component name="libraryTable"> | |
<library name="javax.servlet.jsp.jstl-1.2.1-javadoc"> | |
<CLASSES /> | |
<JAVADOC> | |
<root url="jar://$PROJECT_DIR$/web/WEB-INF/lib/javax.servlet.jsp.jstl-1.2.1-javadoc.jar!/" /> | |
</JAVADOC> | |
<SOURCES /> | |
</library> | |
</component> |
<component name="libraryTable"> | |
<library name="jstl"> | |
<CLASSES> | |
<root url="jar://$PROJECT_DIR$/web/WEB-INF/lib/jstl.jar!/" /> | |
</CLASSES> | |
<JAVADOC /> | |
<SOURCES /> | |
</library> | |
</component> |
<component name="libraryTable"> | |
<library name="mysql-connector-java-5.1.37-bin"> | |
<CLASSES> | |
<root url="jar://C:/mysql-connector-java-5.1.37/mysql-connector-java-5.1.37-bin.jar!/" /> | |
</CLASSES> | |
<JAVADOC /> | |
<SOURCES /> | |
</library> | |
</component> |
<component name="libraryTable"> | |
<library name="standard"> | |
<CLASSES> | |
<root url="jar://$PROJECT_DIR$/web/WEB-INF/lib/standard.jar!/" /> | |
</CLASSES> | |
<JAVADOC /> | |
<SOURCES /> | |
</library> | |
</component> |
<component name="libraryTable"> | |
<library name="taglibs-standard-compat-1.2.5"> | |
<CLASSES /> | |
<JAVADOC> | |
<root url="jar://$PROJECT_DIR$/web/WEB-INF/lib/javax.servlet.jsp.jstl-1.2.1-javadoc.jar!/" /> | |
</JAVADOC> | |
<SOURCES /> | |
</library> | |
</component> |
<component name="libraryTable"> | |
<library name="taglibs-standard-jstlel-1.2.5"> | |
<CLASSES /> | |
<JAVADOC /> | |
<SOURCES /> | |
</library> | |
</component> |
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="EntryPointsManager"> | |
<entry_points version="2.0" /> | |
</component> | |
<component name="MavenImportPreferences"> | |
<option name="generalSettings"> | |
<MavenGeneralSettings> | |
<option name="mavenHome" value="Bundled (Maven 3)" /> | |
</MavenGeneralSettings> | |
</option> | |
</component> | |
<component name="ProjectLevelVcsManager" settingsEditedManually="false"> | |
<OptionsSetting value="true" id="Add" /> | |
<OptionsSetting value="true" id="Remove" /> | |
<OptionsSetting value="true" id="Checkout" /> | |
<OptionsSetting value="true" id="Update" /> | |
<OptionsSetting value="true" id="Status" /> | |
<OptionsSetting value="true" id="Edit" /> | |
<ConfirmationsSetting value="0" id="Add" /> | |
<ConfirmationsSetting value="0" id="Remove" /> | |
</component> | |
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |
<output url="file://$PROJECT_DIR$/out" /> | |
</component> | |
</project> |
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/ebookshop.iml" filepath="$PROJECT_DIR$/ebookshop.iml" /> | |
</modules> | |
</component> | |
</project> |
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="Palette2"> | |
<group name="Swing"> | |
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" /> | |
</item> | |
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> | |
</item> | |
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> | |
</item> | |
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true"> | |
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> | |
</item> | |
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" /> | |
<initial-values> | |
<property name="text" value="Button" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> | |
<initial-values> | |
<property name="text" value="RadioButton" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> | |
<initial-values> | |
<property name="text" value="CheckBox" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" /> | |
<initial-values> | |
<property name="text" value="Label" /> | |
</initial-values> | |
</item> | |
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
<preferred-size width="150" height="-1" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
<preferred-size width="150" height="-1" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> | |
<preferred-size width="150" height="-1" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" /> | |
</item> | |
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> | |
<preferred-size width="150" height="50" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> | |
<preferred-size width="200" height="200" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3"> | |
<preferred-size width="200" height="200" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> | |
</item> | |
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" /> | |
</item> | |
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" /> | |
</item> | |
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" /> | |
</item> | |
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1"> | |
<preferred-size width="-1" height="20" /> | |
</default-constraints> | |
</item> | |
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false"> | |
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" /> | |
</item> | |
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false"> | |
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" /> | |
</item> | |
</group> | |
</component> | |
</project> |
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="VcsDirectoryMappings"> | |
<mapping directory="" vcs="" /> | |
</component> | |
</project> |
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="JAVA_MODULE" version="4"> | |
<component name="FacetManager"> | |
<facet type="web" name="Web"> | |
<configuration> | |
<descriptors> | |
<deploymentDescriptor name="context.xml" url="file://$MODULE_DIR$/web/META-INF/context.xml" /> | |
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" /> | |
</descriptors> | |
<webroots> | |
<root url="file://$MODULE_DIR$/web" relative="/" /> | |
</webroots> | |
</configuration> | |
</facet> | |
</component> | |
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |
<exclude-output /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
<orderEntry type="library" scope="PROVIDED" name="JBoss 7.5.0.Final-redhat-21" level="application_server_libraries" /> | |
<orderEntry type="library" exported="" name="standard" level="project" /> | |
<orderEntry type="library" exported="" name="jstl" level="project" /> | |
<orderEntry type="library" exported="" name="mysql-connector-java-5.1.37-bin" level="project" /> | |
<orderEntry type="library" name="javax.servlet.jsp.jstl-1.2.1-javadoc" level="project" /> | |
</component> | |
</module> |
package com.bean; | |
//import java.io.*; | |
import java.sql.*; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.Map; | |
/** | |
* Created by King on 11/27/2015. | |
*/ | |
public class Book { | |
private String title; | |
private int id; | |
private String author; | |
private Double price; | |
private int qty; | |
private String category; | |
private String image; | |
private ArrayList books= new ArrayList(); | |
public Book(String title, int id, String author, Double price, int qty, String category, String image) { | |
this.title = title; | |
this.id = id; | |
this.author = author; | |
this.price = price; | |
this.qty = qty; | |
this.category = category; | |
this.image = image; | |
} | |
public Book(){ | |
setBooks(); | |
} | |
public Book(int id) { | |
this.id = id; | |
} | |
public String getTitle(){ | |
return this.title; | |
} | |
public int getId() { | |
return id; | |
} | |
public String getAuthor() { | |
return author; | |
} | |
public Double getPrice() { | |
return price; | |
} | |
public String getImage() { | |
return image; | |
} | |
public ArrayList getBooks() { | |
return books; | |
} | |
public int getQty() { | |
return qty; | |
} | |
public String getCategory() { | |
return category; | |
} | |
private void setBooks(){ | |
Connection conn = null; | |
Statement stmt = null; | |
try{ | |
//STEP 2: Register JDBC driver | |
Class.forName("com.mysql.jdbc.Driver"); | |
//STEP 3: Open a connection | |
// System.out.println("Connecting to database..."); | |
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ebookshop","root",""); | |
//STEP 4: Execute a query | |
// System.out.println("Creating statement..."); | |
stmt = conn.createStatement(); | |
String sql; | |
sql = "select * from books where 1"; | |
ResultSet rs = stmt.executeQuery(sql); | |
//STEP 5: Extract data from result set | |
while(rs.next()){ | |
//Retrieve by column name | |
int idi = rs.getInt("id"); | |
String titlei = rs.getString("title"); | |
String authori = rs.getString("author"); | |
Double pricei = rs.getDouble("price"); | |
int qtyi = rs.getInt("qty"); | |
String categoryi = rs.getString("category"); | |
String imagei = rs.getString("image"); | |
Map currentBook = new HashMap(); | |
currentBook.put("id", idi); | |
currentBook.put("title", titlei); | |
currentBook.put("author", authori); | |
currentBook.put("price", pricei); | |
currentBook.put("qty", qtyi); | |
currentBook.put("category", categoryi); | |
currentBook.put("image", imagei); | |
books.add(currentBook); | |
//Display values | |
// System.out.println("Last: " + title); | |
} | |
//STEP 6: Clean-up environment | |
rs.close(); | |
stmt.close(); | |
conn.close(); | |
}catch(SQLException se){ | |
//Handle errors for JDBC | |
se.printStackTrace(); | |
}catch(Exception e){ | |
//Handle errors for Class.forName | |
e.printStackTrace(); | |
}finally{ | |
//finally block used to close resources | |
try{ | |
if(stmt!=null) | |
stmt.close(); | |
}catch(SQLException se2){ | |
}// nothing we can do | |
try{ | |
if(conn!=null) | |
conn.close(); | |
}catch(SQLException se){ | |
se.printStackTrace(); | |
}//end finally try | |
}//end try | |
// System.out.println("Goodbye!"); | |
if(this.title == null) | |
this.title = "not Set"; | |
} | |
private void setId(){ | |
Connection conn = null; | |
Statement stmt = null; | |
try{ | |
//STEP 2: Register JDBC driver | |
Class.forName("com.mysql.jdbc.Driver"); | |
//STEP 3: Open a connection | |
// System.out.println("Connecting to database..."); | |
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ebookshop","root",""); | |
//STEP 4: Execute a query | |
// System.out.println("Creating statement..."); | |
stmt = conn.createStatement(); | |
String sql; | |
sql = "select * from books where id =" + this.id; | |
ResultSet rs = stmt.executeQuery(sql); | |
//STEP 5: Extract data from result set | |
while(rs.next()){ | |
//Retrieve by column name | |
title = rs.getString("title"); | |
author = rs.getString("author"); | |
price = rs.getDouble("price"); | |
qty = rs.getInt("qty"); | |
//Display values | |
// System.out.println("Last: " + title); | |
} | |
//STEP 6: Clean-up environment | |
rs.close(); | |
stmt.close(); | |
conn.close(); | |
}catch(SQLException se){ | |
//Handle errors for JDBC | |
se.printStackTrace(); | |
}catch(Exception e){ | |
//Handle errors for Class.forName | |
e.printStackTrace(); | |
}finally{ | |
//finally block used to close resources | |
try{ | |
if(stmt!=null) | |
stmt.close(); | |
}catch(SQLException se2){ | |
}// nothing we can do | |
try{ | |
if(conn!=null) | |
conn.close(); | |
}catch(SQLException se){ | |
se.printStackTrace(); | |
}//end finally try | |
}//end try | |
// System.out.println("Goodbye!"); | |
if(this.title == null) | |
this.title = "not Set"; | |
} | |
} |
package com.bean; | |
import java.sql.*; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
import java.util.Map; | |
/** | |
* Created by King on 12/1/2015. | |
*/ | |
public class Category { | |
private String category; | |
private ArrayList categoryList = new ArrayList(); | |
private ArrayList categoryBooks = new ArrayList(); | |
public Category() { | |
setCategoryList(); | |
} | |
public String getCategory() { | |
return category; | |
} | |
public void setCategory(String category) { | |
this.category = category; | |
} | |
public ArrayList getCategoryList() { | |
return categoryList; | |
} | |
public void setCategoryList() { | |
Connection conn = null; | |
Statement stmt = null; | |
ArrayList newList = new ArrayList(); | |
try{ | |
//STEP 2: Register JDBC driver | |
Class.forName("com.mysql.jdbc.Driver"); | |
//STEP 3: Open a connection | |
// System.out.println("Connecting to database..."); | |
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ebookshop", "root", ""); | |
//STEP 4: Execute a query | |
// System.out.println("Creating statement..."); | |
stmt = conn.createStatement(); | |
String sql; | |
sql = "select id, category from books where 1 GROUP BY category"; | |
ResultSet rs = stmt.executeQuery(sql); | |
//STEP 5: Extract data from result set | |
while(rs.next()){ | |
//Retrieve by column name | |
int idi = rs.getInt("id"); | |
String categoryi = rs.getString("category"); | |
Map currentBook = new HashMap(); | |
currentBook.put("id", idi); | |
currentBook.put("category", categoryi); | |
newList.add(currentBook); | |
// System.out.println(); | |
} | |
//STEP 6: Clean-up environment | |
rs.close(); | |
stmt.close(); | |
conn.close(); | |
}catch(SQLException se){ | |
//Handle errors for JDBC | |
se.printStackTrace(); | |
}catch(Exception e){ | |
//Handle errors for Class.forName | |
e.printStackTrace(); | |
}finally{ | |
//finally block used to close resources | |
try{ | |
if(stmt!=null) | |
stmt.close(); | |
}catch(SQLException se2){ | |
}// nothing we can do | |
try{ | |
if(conn!=null) | |
conn.close(); | |
}catch(SQLException se){ | |
se.printStackTrace(); | |
}//end finally try | |
}//end try | |
// System.out.println("Goodbye!"); | |
this.categoryList = newList; | |
} | |
public ArrayList getCategoryBooks() { | |
return categoryBooks; | |
} | |
public void setCategoryBooks(String category) { | |
ArrayList newbooks = new ArrayList(); | |
Connection conn = null; | |
Statement stmt = null; | |
try{ | |
//STEP 2: Register JDBC driver | |
Class.forName("com.mysql.jdbc.Driver"); | |
//STEP 3: Open a connection | |
// System.out.println("Connecting to database..."); | |
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/ebookshop","root",""); | |
//STEP 4: Execute a query | |
// System.out.println("Creating statement..."); | |
stmt = conn.createStatement(); | |
String sql; | |
sql = "select * from books where category = \"" + category + "\" "; | |
ResultSet rs = stmt.executeQuery(sql); | |
//STEP 5: Extract data from result set | |
while(rs.next()){ | |
//Retrieve by column name | |
int idi = rs.getInt("id"); | |
String titlei = rs.getString("title"); | |
String authori = rs.getString("author"); | |
Double pricei = rs.getDouble("price"); | |
int qtyi = rs.getInt("qty"); | |
String categoryi = rs.getString("category"); | |
String imagei = rs.getString("image"); | |
Map currentBook = new HashMap(); | |
currentBook.put("id", idi); | |
currentBook.put("title", titlei); | |
currentBook.put("author", authori); | |
currentBook.put("price", pricei); | |
currentBook.put("qty", qtyi); | |
currentBook.put("category", categoryi); | |
currentBook.put("image", imagei); | |
newbooks.add(currentBook); | |
//Display values | |
// System.out.println("Last: " + title); | |
} | |
//STEP 6: Clean-up environment | |
rs.close(); | |
stmt.close(); | |
conn.close(); | |
}catch(SQLException se){ | |
//Handle errors for JDBC | |
se.printStackTrace(); | |
}catch(Exception e){ | |
//Handle errors for Class.forName | |
e.printStackTrace(); | |
}finally{ | |
//finally block used to close resources | |
try{ | |
if(stmt!=null) | |
stmt.close(); | |
}catch(SQLException se2){ | |
}// nothing we can do | |
try{ | |
if(conn!=null) | |
conn.close(); | |
}catch(SQLException se){ | |
se.printStackTrace(); | |
}//end finally try | |
}//end try | |
// System.out.println("Goodbye!"); | |
this.categoryBooks = newbooks; | |
} | |
} |
package com.router; | |
import com.bean.*; | |
import javax.servlet.*; | |
import javax.servlet.http.*; | |
import java.io.*; | |
import java.util.ArrayList; | |
public class welcome extends HttpServlet{ | |
public void doGet(HttpServletRequest request, HttpServletResponse response) | |
throws IOException, ServletException{ | |
String page = request.getParameter("page"); | |
String category = request.getParameter("category"); | |
String gotAuthor = request.getParameter("author"); | |
Book newBook = new Book(); | |
ArrayList booksList = newBook.getBooks(); | |
Authors authors = new Authors(); | |
ArrayList allAuthors = authors.getAuthorList(); | |
Category categories = new Category(); | |
ArrayList allCategories = categories.getCategoryList(); | |
// System.out.println(allAuthors.get(0)); | |
request.setAttribute("book", booksList); | |
request.setAttribute("authors", allAuthors); | |
request.setAttribute("categories", allCategories); | |
if(page == null || page.isEmpty()){ | |
page = "main"; | |
} | |
// else if (page == "category"){ | |
categories.setCategoryBooks(category); | |
ArrayList categoryBooks = categories.getCategoryBooks(); | |
request.setAttribute("categorybooks", categoryBooks); | |
authors.setAuthorbooks(gotAuthor); | |
ArrayList authorBooks = authors.getAuthorbooks(); | |
request.setAttribute("authorbooks", authorBooks); | |
// page = "category"; | |
// request.setAttribute("category", category); | |
// } | |
request.setAttribute("category", category); | |
request.setAttribute("page", page); | |
request.setAttribute("author", gotAuthor); | |
RequestDispatcher view=request.getRequestDispatcher("index.jsp"); | |
view.forward(request, response); | |
} | |
} | |
<%--<c:choose>--%> | |
<%--<c:when "${page.Link=='category'}">--%> | |
<%--<jsp:include page="includes/main.jsp" />--%> | |
<%--</c:when>--%> | |
<%--<c:otherwise>--%> | |
<%--<jsp:include page="includes/main.jsp" />--%> | |
<%--</c:otherwise>--%> | |
<%--</c:choose>--%> |
<?xml version="1.0" encoding="UTF-8"?> | |
<Context path="/"> | |
</Context> |
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
(Sorry about that, but we can’t show files that are this big right now.)
PK | |