Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dkproduction;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import com.wowza.wms.logging.WMSLogger;
- import com.wowza.wms.logging.WMSLoggerFactory;
- public class DBClass {
- private static Connection conn;
- private static final String connString = "jdbc:mysql://localhost:3306/tokentest?user=root";
- private static WMSLogger log;
- public DBClass() {
- log = WMSLoggerFactory.getLogger(null);
- log.info("DatabaseClass Awakened!");
- }
- // Så snart jeg kalder den her metode fra ModuleMain klassen, så får jeg en Reflection Exception!
- public static Token getTokenByUsername(String username) {
- conn = null;
- Token token = null;
- String tokenText = "", timestamp = "", tokenExpire = "", oldToken = "", oldTokenTimeStamp = "",
- oldTokenExpire = "", banned = "";
- try {
- conn = DriverManager.getConnection(connString);
- String query = "SELECT * FROM token WHERE username='" + username + "'";
- PreparedStatement prepState = null;
- ResultSet rs = null;
- try {
- prepState = conn.prepareStatement(query);
- rs = prepState.executeQuery();
- while (rs.next()) {
- tokenText = rs.getString("token_text");
- timestamp = rs.getString("time_stamp");
- tokenExpire = rs.getString("token_expire");
- oldToken = rs.getString("old_token_text");
- oldTokenTimeStamp = rs.getString("old_token_time_stamp");
- oldTokenExpire = rs.getString("old_token_expire");
- banned = rs.getString("banned");
- }
- rs.close();
- token = new Token(username, tokenText, timestamp, tokenExpire, oldToken, oldTokenTimeStamp,
- oldTokenExpire, banned);
- return token;
- } catch (Exception e) {
- System.out.println(e.getMessage());
- return null;
- }
- } catch (Exception e) {
- System.out.println(e.getMessage());
- return null;
- } finally {
- if (conn != null) {
- try {
- conn.close();
- } catch (Exception e) {
- // Do error handling here
- System.out.println("Closing Connection Error\n" + e.getMessage());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement