Skip to content

Commit e81e9ae

Browse files
committed
Added Java project
1 parent 666ec7d commit e81e9ae

File tree

5 files changed

+110
-0
lines changed

5 files changed

+110
-0
lines changed

.classpath

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5+
<classpathentry kind="lib" path="C:/Users/Tommaso/Desktop/mysql-connector-java-5.1.39-bin.jar"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>MotoDB</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.motodb.controller;
2+
import java.sql.Connection;
3+
import java.sql.SQLException;
4+
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
5+
6+
public class DBManager {
7+
8+
// Info connessioni DB
9+
private static final String dbName = "MotoDB";
10+
private static final String url = "motodb.c1s5lipxxzvy.eu-west-1.rds.amazonaws.com";
11+
private static final String username = "Administrator";
12+
private static final String password = "cocomero";
13+
private Connection connection;
14+
private MysqlDataSource dataSource;
15+
16+
public Connection getConnection() {
17+
18+
dataSource = new MysqlDataSource();
19+
dataSource.setUser(username);
20+
dataSource.setPassword(password);
21+
dataSource.setServerName(url);
22+
dataSource.setDatabaseName(dbName);
23+
24+
try {
25+
Class.forName("com.mysql.jdbc.Driver").newInstance();
26+
} catch (Exception e) {
27+
e.printStackTrace();
28+
}
29+
30+
try {
31+
this.connection = dataSource.getConnection();
32+
} catch (SQLException e) {
33+
e.printStackTrace();
34+
}
35+
return this.connection;
36+
}
37+
38+
public void closeConnection() {
39+
try {
40+
this.connection.close();
41+
} catch (SQLException e) {
42+
e.printStackTrace();
43+
}
44+
}
45+
46+
}

src/com/motodb/controller/Test.java

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.motodb.controller;
2+
import java.sql.Connection;
3+
import java.sql.ResultSet;
4+
import java.sql.SQLException;
5+
import java.sql.Statement;
6+
7+
public class Test {
8+
9+
public static void main(String[] args) {
10+
// TODO Auto-generated method stub
11+
DBManager db = new DBManager();
12+
Connection conn = db.getConnection();
13+
14+
ResultSet rs;
15+
try {
16+
Statement stmt = conn.createStatement();
17+
rs = stmt.executeQuery("SELECT * FROM CAMPIONATO");
18+
while (rs.next()) {
19+
System.out.println(rs.getString("anno"));
20+
System.out.println(rs.getString("edizione"));
21+
}
22+
db.closeConnection();
23+
} catch (SQLException e) {
24+
e.printStackTrace();
25+
}
26+
27+
}
28+
29+
}

0 commit comments

Comments
 (0)