Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class ExampleSQL extends Example
- {
- private boolean usehModDb;
- private String dbDriver;
- private String dbUrl;
- private String dbUsername;
- private String dbPassword;
- ExampleSQL(String name, boolean usehModDb)
- {
- super(name);
- this.usehModDb = usehModDb;
- if (!usehModDb)
- {
- PropertiesFile properties = new PropertiesFile("mysql.properties");
- try {
- dbDriver = properties.getString("driver", "com.mysql.jdbc.Driver");
- dbUrl = properties.getString("db", "jdbc:mysql://localhost:3306/minecraft");
- dbUsername = properties.getString("user", "user");
- dbPassword = properties.getString("pass", "pass");
- } catch (Exception ex) {
- log.log(Level.SEVERE, this.getClass().getName() + ": exception while reading from mysql.properties", ex);
- return;
- }
- }
- enabled = checkSchema();
- }
- private Connection getConnection()
- {
- try {
- if (usehModDb)
- return etc.getSQLConnection();
- return DriverManager.getConnection(dbUrl + "?autoReconnect=true&user=" + dbUsername + "&password=" + dbPassword);
- } catch (SQLException ex) {
- log.log(Level.SEVERE, this.getClass().getName() + ": exception while connection to database", ex);
- }
- enabled = false;
- return null;
- }
Add Comment
Please, Sign In to add comment