Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit 208206f

Browse files
committed
wip: fm
1 parent 6441600 commit 208206f

File tree

16 files changed

+87441
-1
lines changed

16 files changed

+87441
-1
lines changed

FarmerMarket/FarmerMarket.iml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="web" name="Web">
5+
<configuration>
6+
<descriptors>
7+
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/webapp/WEB-INF/web.xml" />
8+
</descriptors>
9+
<webroots>
10+
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
11+
</webroots>
12+
<sourceRoots>
13+
<root url="file://$MODULE_DIR$/src/main/resources" />
14+
<root url="file://$MODULE_DIR$/src/main/java" />
15+
</sourceRoots>
16+
</configuration>
17+
</facet>
18+
</component>
19+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
20+
<output url="file://$MODULE_DIR$/target/classes" />
21+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
22+
<content url="file://$MODULE_DIR$">
23+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
24+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
25+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
26+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
27+
<excludeFolder url="file://$MODULE_DIR$/target" />
28+
</content>
29+
<orderEntry type="jdk" jdkName="15" jdkType="JavaSDK" />
30+
<orderEntry type="sourceFolder" forTests="false" />
31+
<orderEntry type="library" exported="" name="Maven: javax.mvc:javax.mvc-api:1.0.0" level="project" />
32+
<orderEntry type="library" exported="" scope="PROVIDED" name="Maven: javax.servlet:javax.servlet-api:4.0.1" level="project" />
33+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.7.0" level="project" />
34+
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
35+
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
36+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.7.0" level="project" />
37+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.7.0" level="project" />
38+
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.7.0" level="project" />
39+
<orderEntry type="module-library">
40+
<library>
41+
<CLASSES>
42+
<root url="file://$MODULE_DIR$/lib" />
43+
</CLASSES>
44+
<JAVADOC />
45+
<SOURCES />
46+
<jarDirectory url="file://$MODULE_DIR$/lib" recursive="false" />
47+
</library>
48+
</orderEntry>
49+
</component>
50+
</module>

FarmerMarket/data/Export.csv

Lines changed: 1538 additions & 0 deletions
Large diffs are not rendered by default.

FarmerMarket/data/zip_codes_states.csv

Lines changed: 42742 additions & 0 deletions
Large diffs are not rendered by default.

FarmerMarket/data/zip_codes_states.sql

Lines changed: 42854 additions & 0 deletions
Large diffs are not rendered by default.

FarmerMarket/docker-compose.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Use root/example as user/password credentials
2+
version: '3.1'
3+
4+
services:
5+
db:
6+
image: mysql
7+
command: --default-authentication-plugin=mysql_native_password
8+
restart: always
9+
ports:
10+
- 3306:3306
11+
environment:
12+
MYSQL_ROOT_PASSWORD: example
13+
14+
adminer:
15+
image: adminer
16+
restart: always
17+
ports:
18+
- 8080:8080
19+
20+
21+
phpmyadmin:
22+
image: phpmyadmin
23+
restart: always
24+
ports:
25+
- 8082:80
26+
environment:
27+
- PMA_ARBITRARY=1
28+
- UPLOAD_LIMIT=300M
1.94 MB
Binary file not shown.

FarmerMarket/pom.xml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.luox6</groupId>
8+
<artifactId>FarmerMarket</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<name>FarmerMarket</name>
11+
<packaging>war</packaging>
12+
13+
<properties>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<junit.version>5.7.0</junit.version>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>javax.mvc</groupId>
22+
<artifactId>javax.mvc-api</artifactId>
23+
<version>1.0.0</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>javax.servlet</groupId>
27+
<artifactId>javax.servlet-api</artifactId>
28+
<version>4.0.1</version>
29+
<scope>provided</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.junit.jupiter</groupId>
33+
<artifactId>junit-jupiter-api</artifactId>
34+
<version>${junit.version}</version>
35+
<scope>test</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.junit.jupiter</groupId>
39+
<artifactId>junit-jupiter-engine</artifactId>
40+
<version>${junit.version}</version>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-war-plugin</artifactId>
50+
<version>3.3.0</version>
51+
</plugin>
52+
</plugins>
53+
</build>
54+
</project>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.luox6.FarmerMarket;
2+
3+
import java.sql.*;
4+
5+
/**
6+
* ADT of a database
7+
*/
8+
public class DB {
9+
private String host;
10+
private String port;
11+
private String user;
12+
private String password;
13+
14+
/**
15+
* Default constructor from host, port, user and password
16+
*
17+
* @param host host of database
18+
* @param port port of database
19+
* @param user user of database
20+
* @param password password of database
21+
*/
22+
public DB(String host, String port, String user, String password) {
23+
this.host = host;
24+
this.port = port;
25+
this.user = user;
26+
this.password = password;
27+
}
28+
29+
/**
30+
* Check if database is connectable to db_name
31+
*
32+
* @param db_name name of database to connect
33+
* @return boolean if database is connectable
34+
*/
35+
public boolean isConnectable(String db_name) {
36+
try {
37+
Class.forName("com.mysql.cj.jdbc.Driver");
38+
}
39+
catch (ClassNotFoundException e) {
40+
e.printStackTrace();
41+
return false;
42+
}
43+
44+
String URL = "jdbc:mysql://" + host + ":" + port + "/" + db_name;
45+
Connection conn = null;
46+
Statement stmt = null;
47+
ResultSet rs = null;
48+
49+
try {
50+
conn = DriverManager.getConnection(URL, user, password);
51+
stmt = conn.createStatement();
52+
stmt.close();
53+
conn.close();
54+
return true;
55+
} catch (SQLException e) {
56+
e.printStackTrace();
57+
return false;
58+
}
59+
}
60+
61+
/**
62+
* Execute cmd as query in database
63+
*
64+
* @param cmd query command
65+
* @return ResultSet of the result of query
66+
*/
67+
public ResultSet runQuery(String cmd) {
68+
String URL = "jdbc:mysql://" + host + ": " + port + "/farmer";
69+
Connection conn = null;
70+
Statement stmt = null;
71+
ResultSet rs = null;
72+
73+
try {
74+
conn = DriverManager.getConnection(URL, user, password);
75+
stmt = conn.createStatement();
76+
rs = stmt.executeQuery(cmd);
77+
return rs;
78+
} catch (SQLException e) {
79+
return null;
80+
}
81+
}
82+
83+
/**
84+
* Main program to test a database
85+
*
86+
* @param args arguments
87+
*/
88+
public static void main(String[] args) {
89+
DB db = new DB("localhost", "3306", "root", "example");
90+
System.out.println(db.isConnectable("farmer"));
91+
ResultSet rset = db.runQuery("SELECT * FROM data WHERE Youtube<>''");
92+
try {
93+
int count = 0;
94+
while (rset.next()) {
95+
String city = rset.getString("city");
96+
System.out.println(city);
97+
count++;
98+
}
99+
System.out.println(count);
100+
} catch (SQLException sqle) {
101+
sqle.printStackTrace();
102+
}
103+
}
104+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.luox6.FarmerMarket;
2+
3+
import java.io.*;
4+
import javax.servlet.http.*;
5+
import javax.servlet.annotation.*;
6+
7+
@WebServlet(name = "helloServlet", value = "/hello-servlet")
8+
public class HelloServlet extends HttpServlet {
9+
private String message;
10+
11+
public void init() {
12+
message = "Hello World!";
13+
}
14+
15+
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
16+
response.setContentType("text/html");
17+
18+
// Hello
19+
PrintWriter out = response.getWriter();
20+
out.println("<html><body>");
21+
out.println("<h1>" + message + "</h1>");
22+
out.println("</body></html>");
23+
}
24+
25+
public void destroy() {
26+
}
27+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
5+
version="4.0">
6+
</web-app>

0 commit comments

Comments
 (0)