-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cf7daa
commit 2deaed8
Showing
3 changed files
with
82 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package routeme.server; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
|
||
import routeme.server.response.ResponseServer; | ||
|
||
public class DatabaseManager { | ||
|
||
protected Properties properties; | ||
|
||
public DatabaseManager() { | ||
try { | ||
System.out.println("Resolving MySQL driver"); | ||
Class.forName("com.mysql.jdbc.Driver"); | ||
} catch (ClassNotFoundException e) { | ||
System.out.println("Unable to load MySQL Driver"); | ||
System.exit(1); | ||
} | ||
|
||
this.properties = this.getProperties(); | ||
} | ||
|
||
public Connection getConnection() { | ||
Connection conn = null; | ||
Properties prop = this.properties; | ||
|
||
try { | ||
System.out.println("Attempting MySQL connection"); | ||
conn = DriverManager.getConnection( | ||
"jdbc:mysql://" + | ||
prop.getProperty("hostname") + "/" + | ||
prop.getProperty("database") + "?" + | ||
"user=" + prop.getProperty("username") + "&" + | ||
"password=" + prop.getProperty("password")); | ||
|
||
} catch (SQLException e) { | ||
System.out.println("Failed to connect to MySQL database"); | ||
System.exit(3); | ||
} | ||
|
||
return conn; | ||
} | ||
|
||
protected Properties getProperties() { | ||
Properties prop = new Properties(); | ||
|
||
try { | ||
prop.load(new FileInputStream("database.properties")); | ||
} catch (IOException e) { | ||
System.out.println("Failed to load database.properties file"); | ||
System.exit(2); | ||
} | ||
return prop; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
RouteMeServer/src/routeme/server/timeline/TimelineServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package routeme.server.timeline; | ||
|
||
public class TimelineServer { | ||
|
||
/** | ||
* @param args | ||
*/ | ||
public static void main(String[] args) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
} |