LectureGame.DataBase
Class DataBaseConnection

java.lang.Object
  extended by LectureGame.DataBase.DataBaseConnection

public class DataBaseConnection
extends java.lang.Object

Created by IntelliJ IDEA. User: olekrst Date: 26.jan.2007 Time: 12:06:26 This class connects to the SQL database. Its primary functionallity is to extract and register new users, and extracting different round and the questions associated with them.

See Also:
Question

Field Summary
private  java.sql.PreparedStatement countQuestionsInRound
           
private  java.sql.PreparedStatement getAllLectures
           
private  java.sql.PreparedStatement getAllRoundsInLecture
           
private  java.sql.PreparedStatement getGameMode
           
private  java.sql.PreparedStatement getQuestion
           
private  java.sql.PreparedStatement newUser
           
private  java.sql.ResultSet rs
           
private  java.sql.Statement stmt
           
 
Constructor Summary
DataBaseConnection()
          Creates a new database connection using com.mysql.jdbc.Driver
 
Method Summary
 void addQuestion(Question question, java.lang.String lectureId)
          NOT IMPLEMENTED Method to be implemented when a Question editor is added
 java.lang.String getAllLectures()
          Extracts all the existing Lectures from the database.
 int getGamgeMode(int roundID)
          Returns the gamemode for a given round
 Question[] getQuestion(int roundID)
          Extracts an array containing all the questions in a lecure
 int[] getRoundsInLecture(int lecture)
          Extracts all the rounds in a given lecture.
 int getUser(java.lang.String usr, java.lang.String password)
          Method for checking username and password.
 int newUser(java.lang.String usr, java.lang.String password)
          Method for creating new users in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rs

private java.sql.ResultSet rs

stmt

private java.sql.Statement stmt

getQuestion

private java.sql.PreparedStatement getQuestion

newUser

private java.sql.PreparedStatement newUser

countQuestionsInRound

private java.sql.PreparedStatement countQuestionsInRound

getAllLectures

private java.sql.PreparedStatement getAllLectures

getAllRoundsInLecture

private java.sql.PreparedStatement getAllRoundsInLecture

getGameMode

private java.sql.PreparedStatement getGameMode
Constructor Detail

DataBaseConnection

public DataBaseConnection()
Creates a new database connection using com.mysql.jdbc.Driver

Method Detail

getGamgeMode

public int getGamgeMode(int roundID)
Returns the gamemode for a given round

Parameters:
roundID - the rund to find the gamemode for
Returns:
the gamemode code (see LG source for constants)
See Also:
LG

getAllLectures

public java.lang.String getAllLectures()
Extracts all the existing Lectures from the database. Formats the return String for sending to the masterclient

Returns:
a string containing all lectures, formatted for sending to the masterclient

addQuestion

public void addQuestion(Question question,
                        java.lang.String lectureId)
NOT IMPLEMENTED Method to be implemented when a Question editor is added

Parameters:
question - the question to add to the database
lectureId - the lectureID of the lecture which will contain the question

getUser

public int getUser(java.lang.String usr,
                   java.lang.String password)
Method for checking username and password. Returns one of the following error codes: - ERROR_USER_EXIST_WRONG_PW; - ERROR_LOGIN_OK - ERROR_UNKNOWN_USER

Parameters:
usr -
password -
Returns:
error code as defined in LG
See Also:
LG

newUser

public int newUser(java.lang.String usr,
                   java.lang.String password)
Method for creating new users in the database. Returns one of the following error codes: - ERROR_LOGIN_OK - ERROR_USERNAME_ALLREADY_EXISTS

Parameters:
usr - the username
password - the password (cannot be "")
Returns:
an error code, as defined in LG constants
See Also:
LG

getRoundsInLecture

public int[] getRoundsInLecture(int lecture)
Extracts all the rounds in a given lecture. Returns the roundIDs of the rounds

Parameters:
lecture -
Returns:
the roundID from the database of the round

getQuestion

public Question[] getQuestion(int roundID)
Extracts an array containing all the questions in a lecure

Parameters:
roundID -
Returns:
Question[] with all lectures in the requested round
See Also:
Question