Merged
This commit is contained in:
commit
d359a3da8f
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@ -6,6 +6,8 @@
|
|||||||
<module name="de.hhn.labsw.BuGaGeocaching.test" target="1.8" />
|
<module name="de.hhn.labsw.BuGaGeocaching.test" target="1.8" />
|
||||||
<module name="de.hhn.labsw.labswp_2019_sose_geocaching.main" target="1.8" />
|
<module name="de.hhn.labsw.labswp_2019_sose_geocaching.main" target="1.8" />
|
||||||
<module name="de.hhn.labsw.labswp_2019_sose_geocaching.test" target="1.8" />
|
<module name="de.hhn.labsw.labswp_2019_sose_geocaching.test" target="1.8" />
|
||||||
|
<module name="labswp_2019_sose_geocaching.de.hhn.labsw.labswp_2019_sose_geocaching.main" target="1.8" />
|
||||||
|
<module name="labswp_2019_sose_geocaching.de.hhn.labsw.labswp_2019_sose_geocaching.test" target="1.8" />
|
||||||
</bytecodeTargetLevel>
|
</bytecodeTargetLevel>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package hhn.labsw.bugageocaching.controller;
|
||||||
|
|
||||||
|
import hhn.labsw.bugageocaching.db.DBConnector;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class Controller {
|
||||||
|
|
||||||
|
@RequestMapping("/")
|
||||||
|
public String test(){
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
58
src/main/java/hhn/labsw/bugageocaching/db/DBConnector.java
Normal file
58
src/main/java/hhn/labsw/bugageocaching/db/DBConnector.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package hhn.labsw.bugageocaching.db;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class DBConnector {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Installation of the web service
|
||||||
|
*
|
||||||
|
* The following parameters have to be changed for setting up the web service in another environment.
|
||||||
|
* DB_HOST = Address of the database. Examples: localhost, 192.168.12.7, mydomain.com
|
||||||
|
* DB_USER = Username for the database connection
|
||||||
|
* DB_PASSWORD = Password for the database connection
|
||||||
|
* DATABASE = Name of the database that shall be used
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final String DB_HOST = "www.se.hs-heilbronn.de:3406/buga19Geocaching";
|
||||||
|
private static final String DB_USER = "BuGa19GeocachingUser";
|
||||||
|
private static final String DB_PASSWORD = "GeocachingPw";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For setting up the Webservice no changes are needed from here!
|
||||||
|
*/
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(DBConnector.class);
|
||||||
|
|
||||||
|
public static Connection connect() {
|
||||||
|
|
||||||
|
logger.debug("Trying to establish connection to database");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("org.mariadb.jdbc.Driver");
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Connect to database
|
||||||
|
*/
|
||||||
|
Connection connection = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
connection = DriverManager.getConnection("jdbc:mariadb://" + DB_HOST + "?user=" + DB_USER + "&password=" + DB_PASSWORD);
|
||||||
|
logger.debug("Connected");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user