Skip to content

Commit

Permalink
Updated the package structure of the project
Browse files Browse the repository at this point in the history
  • Loading branch information
shashirajraja committed Oct 7, 2022
1 parent 9e10be9 commit 45edd52
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 129 deletions.
10 changes: 8 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand All @@ -12,10 +17,11 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src">
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target/
/build/
/target/
/build/
.classpath
.settings
22 changes: 14 additions & 8 deletions .settings/org.eclipse.wst.common.component
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">


<wb-module deploy-name="onlinebookstore">


<wb-module deploy-name="onlinebookstore-0.0.1-SNAPSHOT">

<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>



<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>

<property name="context-root" value="onlinebookstore"/>

<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>


<property name="java-output-path" value="/onlinebookstore/build/classes"/>
</wb-module>
<property name="context-root" value="onlinebookstore"/>

</wb-module>


</project-modules>
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>theonlinebookstore</groupId>
<artifactId>theonlinebookstore</artifactId>
<groupId>onlinebookstore</groupId>
<artifactId>onlinebookstore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>theonlinebookstore</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<finalName>onlinebookstore</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/config/DBConnection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package config;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnection {
private static Connection con;

private DBConnection() {
};

static {

try {

Class.forName(DatabaseConfig.DRIVER_NAME);

} catch (Exception e) {
e.printStackTrace();
}

try {

con = DriverManager.getConnection(DatabaseConfig.CONNECTION_STRING, DatabaseConfig.DB_USER_NAME,
DatabaseConfig.DB_PASSWORD);

} catch (SQLException e) {

e.printStackTrace();

}

}// End of static block

public static Connection getCon() {
return con;
}
}
14 changes: 14 additions & 0 deletions src/main/java/config/DatabaseConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package config;

public class DatabaseConfig {

public static final String DRIVER_NAME ="com.mysql.jdbc.Driver";
public static final String DB_HOST = "jdbc:mysql://localhost";
public static final String DB_PORT = "3306";
public static final String DB_NAME = "onlinebookstore";
public static final String DB_USER_NAME = "root";
public static final String DB_PASSWORD = "root";

public static final String CONNECTION_STRING = DB_HOST + ":" + DB_PORT + "/" + DB_NAME;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package constants;

public interface IOnlineBookStoreConstants {
public interface BookStoreConstants {
public static String CONTENT_TYPE_TEXT_HTML = "text/html";


Expand Down
10 changes: 0 additions & 10 deletions src/main/java/constants/IDatabase.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sql;
package constants.db;

public interface IBookConstants {
public interface BooksDBConstants {

public static String TABLE_BOOK = "books";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sql;
package constants.db;

public interface IUserContants {
public interface UsersDBConstants {

public static String TABLE_USERS = "users";

Expand Down
19 changes: 10 additions & 9 deletions src/main/java/servlets/AddBookServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import constants.IOnlineBookStoreConstants;
import sql.IBookConstants;
import config.DBConnection;
import constants.BookStoreConstants;
import constants.db.BooksDBConstants;

public class AddBookServlet extends GenericServlet{
public void service(ServletRequest req,ServletResponse res) throws IOException,ServletException
{
PrintWriter pw = res.getWriter();

res.setContentType(IOnlineBookStoreConstants.CONTENT_TYPE_TEXT_HTML);
res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML);

String bCode = req.getParameter(IBookConstants.COLUMN_BARCODE);
String bName = req.getParameter(IBookConstants.COLUMN_NAME);
String bAuthor = req.getParameter(IBookConstants.COLUMN_AUTHOR);
int bPrice =Integer.parseInt(req.getParameter(IBookConstants.COLUMN_PRICE));
int bQty = Integer.parseInt(req.getParameter(IBookConstants.COLUMN_QUANTITY));
String bCode = req.getParameter(BooksDBConstants.COLUMN_BARCODE);
String bName = req.getParameter(BooksDBConstants.COLUMN_NAME);
String bAuthor = req.getParameter(BooksDBConstants.COLUMN_AUTHOR);
int bPrice =Integer.parseInt(req.getParameter(BooksDBConstants.COLUMN_PRICE));
int bQty = Integer.parseInt(req.getParameter(BooksDBConstants.COLUMN_QUANTITY));

try {
Connection con = DBConnection.getCon();
PreparedStatement ps = con.prepareStatement("insert into " + IBookConstants.TABLE_BOOK + " values(?,?,?,?,?)");
PreparedStatement ps = con.prepareStatement("insert into " + BooksDBConstants.TABLE_BOOK + " values(?,?,?,?,?)");
ps.setString(1, bCode);
ps.setString(2, bName);
ps.setString(3, bAuthor);
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/servlets/AdminLoginServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;

import constants.IOnlineBookStoreConstants;
import sql.IUserContants;
import config.DBConnection;
import constants.BookStoreConstants;
import constants.db.UsersDBConstants;

import java.io.*;
import java.sql.*;

public class AdminLoginServlet extends GenericServlet {
public void service(ServletRequest req, ServletResponse res) throws IOException, ServletException {
PrintWriter pw = res.getWriter();
res.setContentType(IOnlineBookStoreConstants.CONTENT_TYPE_TEXT_HTML);
String uName = req.getParameter(IUserContants.COLUMN_USERNAME);
String pWord = req.getParameter(IUserContants.COLUMN_PASSWORD);
res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML);
String uName = req.getParameter(UsersDBConstants.COLUMN_USERNAME);
String pWord = req.getParameter(UsersDBConstants.COLUMN_PASSWORD);
try {
Connection con = DBConnection.getCon();
PreparedStatement ps = con.prepareStatement("SELECT * FROM " + IUserContants.TABLE_USERS + " WHERE "
+ IUserContants.COLUMN_USERNAME + "=? AND " + IUserContants.COLUMN_PASSWORD + "=? AND "
+ IUserContants.COLUMN_USERTYPE + "=1");
PreparedStatement ps = con.prepareStatement("SELECT * FROM " + UsersDBConstants.TABLE_USERS + " WHERE "
+ UsersDBConstants.COLUMN_USERNAME + "=? AND " + UsersDBConstants.COLUMN_PASSWORD + "=? AND "
+ UsersDBConstants.COLUMN_USERTYPE + "=1");
ps.setString(1, uName);
ps.setString(2, pWord);
ResultSet rs = ps.executeQuery();
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/servlets/BuyBooksServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import java.sql.*;
import javax.servlet.*;

import constants.IOnlineBookStoreConstants;
import sql.IBookConstants;
import sql.IUserContants;
import config.DBConnection;
import constants.BookStoreConstants;
import constants.db.BooksDBConstants;
import constants.db.UsersDBConstants;
public class BuyBooksServlet extends GenericServlet{
public void service(ServletRequest req,ServletResponse res) throws IOException,ServletException
{
PrintWriter pw = res.getWriter();
res.setContentType(IOnlineBookStoreConstants.CONTENT_TYPE_TEXT_HTML);
res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML);
try {
Connection con = DBConnection.getCon();
//ArrayList<Books> al = new ArrayList<Books>();
PreparedStatement ps = con.prepareStatement("Select * from " + IBookConstants.TABLE_BOOK);
PreparedStatement ps = con.prepareStatement("Select * from " + BooksDBConstants.TABLE_BOOK);
ResultSet rs = ps.executeQuery();
RequestDispatcher rd = req.getRequestDispatcher("ViewBooks.html");
rd.include(req, res);
Expand Down
42 changes: 0 additions & 42 deletions src/main/java/servlets/DBConnection.java

This file was deleted.

23 changes: 12 additions & 11 deletions src/main/java/servlets/ReceiptServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import java.io.*;
import javax.servlet.*;

import constants.IOnlineBookStoreConstants;
import sql.IBookConstants;
import config.DBConnection;
import constants.BookStoreConstants;
import constants.db.BooksDBConstants;

public class ReceiptServlet extends GenericServlet {
public void service(ServletRequest req, ServletResponse res) throws IOException, ServletException {
PrintWriter pw = res.getWriter();
res.setContentType(IOnlineBookStoreConstants.CONTENT_TYPE_TEXT_HTML);
res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML);
try {
Connection con = DBConnection.getCon();
PreparedStatement ps = con.prepareStatement("select * from " + IBookConstants.TABLE_BOOK);
PreparedStatement ps = con.prepareStatement("select * from " + BooksDBConstants.TABLE_BOOK);
ResultSet rs = ps.executeQuery();
int i = 0;
RequestDispatcher rd = req.getRequestDispatcher("ViewBooks.html");
Expand All @@ -26,11 +27,11 @@ public void service(ServletRequest req, ServletResponse res) throws IOException,
+ " <th>Quantity</th><br/>\r\n" + " <th>Amount</th><br/>\r\n" + " </tr>");
double total = 0.0;
while (rs.next()) {
int bPrice = rs.getInt(IBookConstants.COLUMN_PRICE);
String bCode = rs.getString(IBookConstants.COLUMN_BARCODE);
String bName = rs.getString(IBookConstants.COLUMN_NAME);
String bAuthor = rs.getString(IBookConstants.COLUMN_AUTHOR);
int bQty = rs.getInt(IBookConstants.COLUMN_QUANTITY);
int bPrice = rs.getInt(BooksDBConstants.COLUMN_PRICE);
String bCode = rs.getString(BooksDBConstants.COLUMN_BARCODE);
String bName = rs.getString(BooksDBConstants.COLUMN_NAME);
String bAuthor = rs.getString(BooksDBConstants.COLUMN_AUTHOR);
int bQty = rs.getInt(BooksDBConstants.COLUMN_QUANTITY);
i = i + 1;

String qt = "qty" + Integer.toString(i);
Expand All @@ -55,8 +56,8 @@ public void service(ServletRequest req, ServletResponse res) throws IOException,
pw.println("<td>" + amount + "</td></tr>");
bQty = bQty - quantity;
System.out.println(bQty);
PreparedStatement ps1 = con.prepareStatement("update " + IBookConstants.TABLE_BOOK + " set "
+ IBookConstants.COLUMN_QUANTITY + "=? where " + IBookConstants.COLUMN_BARCODE + "=?");
PreparedStatement ps1 = con.prepareStatement("update " + BooksDBConstants.TABLE_BOOK + " set "
+ BooksDBConstants.COLUMN_QUANTITY + "=? where " + BooksDBConstants.COLUMN_BARCODE + "=?");
ps1.setInt(1, bQty);
ps1.setString(2, bCode);
ps1.executeUpdate();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/servlets/RemoveBookServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.sql.*;
import javax.servlet.*;

import sql.IBookConstants;
import config.DBConnection;
import constants.db.BooksDBConstants;

import java.io.*;

Expand All @@ -15,7 +16,7 @@ public void service(ServletRequest req, ServletResponse res) throws IOException,
try {
Connection con = DBConnection.getCon();
PreparedStatement ps = con.prepareStatement(
"delete from " + IBookConstants.TABLE_BOOK + " where " + IBookConstants.COLUMN_BARCODE + "=?");
"delete from " + BooksDBConstants.TABLE_BOOK + " where " + BooksDBConstants.COLUMN_BARCODE + "=?");
ps.setString(1, bkid);
int k = ps.executeUpdate();
if (k == 1) {
Expand Down
Loading

0 comments on commit 45edd52

Please sign in to comment.