samedi 7 mai 2016

Showing SQLite Database

I'm new to Android development and I'm trying to create a database and inserting element in it through a function putData().
The app is running without any error, but it is not showing any element, just a black Activity.
I don't know what is going wrong, please Help

DBHelper class

    public class DBHelper  extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "food.db";
    public static final String TABLE_NAME = "food_calorie";
    public static final String COL_1 = "ID";
    public static final String COL_2 = "NAME";
    public static final String COL_3 = "CALORIE";

    public DBHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
        SQLiteDatabase db = this.getWritableDatabase();
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table " + TABLE_NAME +" (ID INTEGER PRIMARY KEY AUTOINCREMENT,NAME TEXT,CALORIE INTEGER)");
        putData();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
        onCreate(db);
    }

    public void putData(){
        insertData("Apple", 168);
        insertData("Mango", 194);
    }

    public void insertData(String name, int calorie){
        SQLiteDatabase db=this.getWritableDatabase();
        ContentValues CV=new ContentValues();

        CV.put(COL_2,name);
        CV.put(COL_3,calorie);
        db.insert(TABLE_NAME,null,CV);
        db.close();
    }


    public String printDB(){
        String dbString="";
        SQLiteDatabase db=this.getWritableDatabase();
        String query="SELECT * FROM " + TABLE_NAME + " WHERE 1";

        Cursor c= db.rawQuery(query,null);

        //Move to the first row in your result
        c.moveToFirst();

        while(!c.isAfterLast()){
            if(c.getString(c.getColumnIndex("TABLE_NAME"))!=null){
                dbString+= c.getString(c.getColumnIndex("TABLE_NAME"));
                dbString += "\n";
            }
        }
        db.close();;
        return dbString;
    }
}

MinActivity Class

public class MainActivity extends AppCompatActivity {

    DBHelper MyDb;
    TextView showDBText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        showDBText=(TextView) findViewById(R.id.showDB);
        MyDb = new DBHelper(this);
        printDatabase();
    }
    // Buckys Video 54
    public void printDatabase(){

        //printDB is a function in DBHelper
        String dbString = MyDb.printDB();
        showDBText.setText(dbString);

    }
}

XML file

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Large Text"
            android:id="@+id/showDB"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="4dp" />
</ScrollView>

Android SQliteOpenHelper delete statement issue

Trying to refresh a catalog items table .. just a basic database operation I'm stuck with this strange behaviour

String purgeItems ="DELETE FROM CatalogItems";

String count = "SELECT * FROM CatalogItems";

SQLiteDatabase db = mDb.getWritableDatabase(); // mDb extends SQLiteOpenHelper

db.beginTransaction();
db.rawQuery(purgeItems,null);
db.setTransactionSuccessful();
db.endTransaction();

Cursor c = db.rawQuery(count, null);
Log.e(TAG, "CatalogItems after purge " + String.valueOf(c.getCount()));

returns 642 ..; the original table contant rows count ... ! perhaps I'm tired ^^. it does work with the Products table ...

Select with prepared statements Java

I just learned about prepared statements and now I'm trying to include them to my java program. However I get an exception when I try to add to values to the statement( table and name). When I prepare with only one variable it works fine. What am I doing wrong?

[SQLITE_ERROR] SQL error or missing database (near "?": syntax error) 


String sql="SELECT * FROM ? WHERE name = ?";
    try {
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, table);
        preparedStatement.setString(2, name);
        ResultSet checkTable = preparedStatement.executeQuery();

How do I add a new field to my sqlite3 data base?

I have a javascript file for my data base and I added 2 fields to it(email and password) and exported it to my db.js file like - (the following 2 lines are in my db.js file)

            var db={};
            db.user=sequelize.import(__dirname+'/models/user.js');

my user.js has -

    module.exports = function(sequelize, DataTypes) {
    return sequelize.define('user',{
    email:{
        type:DataTypes.STRING,
        allowNull:false,
        unique:true, //no two same emails
        validate:{
            isEmail:true
        }
    },
    password:{
        type:DataTypes.STRING,
        allowNull:false,
        validate:{
            len:[7,100]
        }
    }

});
      };

If I want to add another field to it say, "displayName", how do i do that? i tried adding

    displayname:{
        type:DataTypes.STRING,
        allowNull:false,
        validate:{
            len:[3,9]
        }
    }

like that after the password field, but when i check the table on sqlitebrowser, nothing gets updated. So how do I do this?

Passing Data With Intent to Search Data Database SQLite

i passing data keyword search with intent for get result in other activity. the keyword search use to search data from database sqlite, but i can't display the result with textView, there is no error in logcat. what problem with my code? there is my code to display output

OutputSuccess.java

package com.mjusuf.halal;

import android.support.v7.app.ActionBarActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class OutputSuccess extends ActionBarActivity {
    // Objects And Variables
    private String select;
    // User Information Variables
    String c2, c3, c4, c5, c6;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_outputsuccess);

        TextView certificate_no = (TextView) findViewById(R.id.textView3);
        TextView valid_from = (TextView) findViewById(R.id.textView6);
        TextView valid_to = (TextView) findViewById(R.id.textView9);
        TextView company = (TextView) findViewById(R.id.textView12);
        TextView product_name = (TextView) findViewById(R.id.textView15);
        // name.setText(getIntent().getExtras().getString("search"));

        DatabaseHandler db = new DatabaseHandler(this);
        SQLiteDatabase db1 = db.getReadableDatabase();
        select = "SELECT * FROM certificate WHERE Certificate_No='"
                + getIntent().getExtras().getString("search") + "'";
        Cursor c1 = db1.rawQuery(select, null);
        if (c1 != null && c1.moveToFirst())
            do {
                certificate_no.setText(c1.getString(c1.getColumnIndex("Certificate_No")));
                valid_from.setText(c1.getString(c1.getColumnIndex("Valid_From")));
                valid_to.setText(c1.getString(c1.getColumnIndex("Valid_To")));
                company.setText(c1.getString(c1.getColumnIndex("Company")));
                product_name.setText(c1.getString(c1.getColumnIndex("Product_Name")));
            } while (c1.moveToNext());
    };

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.output_success, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Issues with PouchDB + SQLite on ionic 2

I followed all the steps for PouchDB setup and SQLite. I am facing following issues:

1) this._db.info().then(console.log.bind(console)) - shows Adapter: websql , sqlite_plugin: false

Object
    adapter:"websql"
    auto_compaction:false
    db_name:"bakbak"
    doc_count:15
    sqlite_plugin:false
    update_seq:15
    websql_encoding:"UTF-8"

I am not sure what i did wrong.

2) App is working fine on Chrome. On firefox it threw an error: this.db.sync is not a function. I changed it to PouchDB.sync then error is gone. Why it happened?

3) On firefox and IE After making above change i am getting "EXCEPTION: Error: Uncaught (in promise): Error: Adapter is missing".

is this bug resolved: http://ift.tt/1WguRaQ

I tried to follow the advice here: Ionic PouchDb Sqlite plugin issue

But i do not have any pouchdb library imported in my index.html. It is not there in js folder. I can find it in node-modules folder.

<body>
<ion-app></ion-app>
<!-- cordova.js required for cordova apps -->
<script src="cordova.js"></script>
<!-- Polyfill needed for platforms without Promise and Collection support   -->
<script src="build/js/es6-shim.min.js"></script>
<!-- Zone.js and Reflect-metadata  -->
<script src="build/js/angular2-polyfills.js"></script>
<!-- the bundle which is built from the app's source code -->
<script src="build/js/app.bundle.js"></script>
</body>

Sqlite: Unable to open the database file (out of memory) when I separated one class into three

I had a class called GUI which contained all of the code. I decided I wanted to separate it in 3 classes: GUI, teacher, student. The problem is that in the new separated version, I can't manage to connect the databases because I get this error: [SQLITE_CANTOPEN] Unable to open the database file (out of memory).

This is how my classes look:

GUI

public class GUI extends Application
{
//Grid Panels
GridPane chooseUserButtonPane;

//Titles
Image chooseUser;

//Choose User
Button teacherButton;
Button studentButton;
Button backButton;

//Instances of other classes
Teacher teacher = new Teacher();
Student student = new Student();

//Scenes
Scene sceneChooseUser;

Stage primaryStage = new Stage();




public static void main(String[] args)
{
    //when you open GUI is going to call the method launch then 
    //is going to go to the application and its going to set the program as a javafx application
    launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception 
{

    //Primary stage = main window
    primaryStage.setTitle("Carmen Zarco Lens");

    //Creating the layout of the Choose User page.
    StackPane layoutChooseUser = new StackPane();
    layoutChooseUser.setStyle("-fx-background-color: #FECB6E;");


    //Scene of the LogIn window
    sceneChooseUser = new Scene(layoutChooseUser, 1100, 650);


    //This says use our scene for the primary stage
    primaryStage.setScene(sceneChooseUser);



    //CHOOSE USER SCENE

    //Choose user title  
    AnchorPane chooseUserPane = new AnchorPane();
    chooseUser = new Image(getClass().getResourceAsStream("chooseUser.png"));
    ImageView chooseUsertitleview = new ImageView();
    chooseUsertitleview.setImage(chooseUser);
    chooseUserPane.getChildren().add(chooseUsertitleview);
    ImageView chooseUsertitleapp = (ImageView) chooseUserPane.getChildren().get(0);
    chooseUsertitleapp.setX(150);
    chooseUsertitleapp.setY(10);

    //top/right/bottom/left
   //Choose User buttons panel
    chooseUserButtonPane = new GridPane();
    chooseUserButtonPane.setHgap(100); 
    chooseUserButtonPane.setVgap(25); 
    chooseUserButtonPane.setPadding(new Insets(200, 20, 0, 80));


    teacherButton = new Button("TEACHER ACCOUNT");
    teacherButton.setOnAction(e -> primaryStage.setScene(teacher.sceneTLogIn));
    teacherButton.setPrefWidth(320.0);
    teacherButton.setPrefHeight(320.0);
    teacherButton.setStyle("-fx-font: 50 timesnewroman; -fx-base: #AE3522");
    teacherButton.setWrapText(true);

    chooseUserButtonPane.add(teacherButton,1,1);

    studentButton = new Button("STUDENT ACCOUNT");
    studentButton.setOnAction(e -> primaryStage.setScene(student.sceneSLogIn));
    studentButton.setPrefWidth(320.0);
    studentButton.setPrefHeight(320.0);
    studentButton.setStyle("-fx-font: 50 timesnewroman; -fx-base: #AE3522");
    studentButton.setWrapText(true);

    chooseUserButtonPane.add(studentButton,2,1);




    //ADD EVERYTHING TO THE LAYOUTS

    //Add things to the choose User layout
    layoutChooseUser.getChildren().add(chooseUserPane);
    layoutChooseUser.getChildren().add(chooseUserButtonPane);


    // Displays it to the user
    primaryStage.setResizable(false);
    primaryStage.show();

}

}

TEACHER

 public class Teacher
 {
//Title 
Image Tlogin; 
Image title;
Image addQuestions;
Image Tsignup;


//Grid Panels
GridPane TloginButtonPane;
GridPane TsignupButtonPane;
GridPane addQButtonPane;
GridPane backButtonPane;


//Teacher Login 
TextField userTextFieldT;
PasswordField passwordTextFieldT;
Button TloginButton;
Button TsignupButton;
Label TloginProblemLabel;
Button backButton;  

//Teacher SignUp
Label nameSignupTLabel;
TextField nameSignupTTextField;
Label lastnameSignupTLabel;
TextField lastnameSignupTTextField;
Label usernameSignupTLabel;
TextField usernameSignupTTextField;
Label passwordSignupTLabel;
TextField passwordSignupTTextField;
Button saveTButton;

//Add Question
Label typeQLabel;
Label subjectLabel;
RadioButton mathRB;
RadioButton historyRB;
RadioButton geographyRB;
RadioButton sciencesRB;
RadioButton spanishRB;
RadioButton physicsRB;
String textSubjectQ;
RadioButton typeQ1;
RadioButton typeQ2;
RadioButton typeQ3;
String textTypeQ;
Label levelLabel;
ToggleButton easyLevelButton;
ToggleButton mediumLevelButton;
ToggleButton highLevelButton;
String textLevelQ;
Label speedLabel;
String textSpeedQ;
TextField speedTextField;
Label contentQLabel;
TextField contentQTextField;
Label answerQLabel;
static TextField answerQTextField;
Button doneButton;
Button addQButton;
Label problemLabel;
Label questionTextLabel;

//Connecting to the databases
Connection connectionQuestions = null;
Connection connectionUsers = null;

//Instance GUI
GUI gui;

//Scenes
Scene sceneTLogIn;


public Teacher()
{
    connectionQuestions = questionssqliteConnection.dbConnector();
    connectionUsers = userssqliteConnection.UdbConnector();
    gui = new GUI();
}


public void main(String[] args)
{
    //Creating the layout of the Teacher LogIn page.
    StackPane layoutTLogIn = new StackPane();
    layoutTLogIn.setStyle("-fx-background-color: #FECB6E;");

    //Creating the layout of the teachers SignUp.
    StackPane layoutTSignUp = new StackPane();
    layoutTSignUp.setStyle("-fx-background-color: #FECB6E;");

    //Creating the layout of the Teacher LogIn page.
    StackPane layoutAddQ = new StackPane();
    layoutAddQ.setStyle("-fx-background-color: #FECB6E;");



    //Scene of the Teacher LogIn window
    sceneTLogIn = new Scene(layoutTLogIn, 1100, 650);

    //Scene of the Teacher SignUP window
    Scene sceneTSignUp = new Scene(layoutTSignUp, 1100, 650);

    //Scene of the Teacher to add questions to the database
    Scene sceneAddQ = new Scene(layoutAddQ, 1100, 650);





    //TEACHER SIGN UP SCENE


  //Login title  
    AnchorPane TsignupPane = new AnchorPane();
    Tsignup = new Image(getClass().getResourceAsStream("singup.png"));
    ImageView Tsignuptitleview = new ImageView();
    Tsignuptitleview.setImage(Tsignup);
    TsignupPane.getChildren().add(Tsignuptitleview);
    ImageView Tsignuptitleapp = (ImageView) TsignupPane.getChildren().get(0);
    Tsignuptitleapp.setX(300);
    Tsignuptitleapp.setY(10);


    //top/right/bottom/left
    //Teacher signup buttons panel
    TsignupButtonPane = new GridPane();
    TsignupButtonPane.setHgap(50); 
    TsignupButtonPane.setVgap(30); 
    TsignupButtonPane.setPadding(new Insets(150, 10, 0, 140));



    nameSignupTLabel = new Label("First Name:");
    nameSignupTLabel.setPrefWidth(250.0);
    nameSignupTLabel.setPrefHeight(50.0);
    nameSignupTLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");

    TsignupButtonPane.add(nameSignupTLabel,1,1);



    nameSignupTTextField = new TextField();
    nameSignupTTextField.setPrefWidth(400.0);
    nameSignupTTextField.setPrefHeight(60.0);
    nameSignupTTextField.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");

    TsignupButtonPane.add(nameSignupTTextField,2,1);



    lastnameSignupTLabel = new Label("Last Name:");
    lastnameSignupTLabel.setPrefWidth(250.0);
    lastnameSignupTLabel.setPrefHeight(50.0);
    lastnameSignupTLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");

    TsignupButtonPane.add(lastnameSignupTLabel,1,2);



    lastnameSignupTTextField = new TextField();
    lastnameSignupTTextField.setPrefWidth(400.0);
    lastnameSignupTTextField.setPrefHeight(60.0);
    lastnameSignupTTextField.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");

    TsignupButtonPane.add(lastnameSignupTTextField,2,2);



    usernameSignupTLabel = new Label("UserName:");
    usernameSignupTLabel.setPrefWidth(250.0);
    usernameSignupTLabel.setPrefHeight(50.0);
    usernameSignupTLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");

    TsignupButtonPane.add(usernameSignupTLabel,1,3);



    usernameSignupTTextField = new TextField();
    usernameSignupTTextField.setPrefWidth(400.0);
    usernameSignupTTextField.setPrefHeight(60.0);
    usernameSignupTTextField.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");

    TsignupButtonPane.add(usernameSignupTTextField,2,3);



    passwordSignupTLabel = new Label("Password:");
    passwordSignupTLabel.setPrefWidth(250.0);
    passwordSignupTLabel.setPrefHeight(50.0);
    passwordSignupTLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");

    TsignupButtonPane.add(passwordSignupTLabel,1,4);



    passwordSignupTTextField = new TextField();
    passwordSignupTTextField.setPrefWidth(400.0);
    passwordSignupTTextField.setPrefHeight(60.0);
    passwordSignupTTextField.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522; -fx-text-fill: black;");

    TsignupButtonPane.add(passwordSignupTTextField,2,4);

    saveTButton = new Button("SAVE INFORMATION");
    saveTButton.addEventHandler(ActionEvent.ACTION, (e)-> {

        try
        {
            String query = "insert into TeachersInfo (\"First Name\",\"Last Name\",UserName,Password) values (?,?,?,?)";
            //String query = "insert into TeachersInfo (First Name,Last Name,UserName,Password) values (?,?,?,?)";
            PreparedStatement pst = connectionUsers.prepareStatement(query);
            //First question mark = 1, second = 2, etc.
            pst.setString(1,nameSignupTTextField.getText());
            pst.setString(2,lastnameSignupTTextField.getText());
            pst.setString(3,usernameSignupTTextField.getText());
            pst.setString(4,passwordSignupTTextField.getText());


            pst.execute();

            System.out.println("Data saved");

            //after executing the query this lines will close the connection with the database
            pst.close();

        }
        catch(Exception a)
        {
            System.out.println(a);
        }

        gui.primaryStage.setScene(gui.sceneChooseUser);
    });
    saveTButton.setPrefWidth(700.0);
    saveTButton.setPrefHeight(60.0);
    saveTButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522;;");

    TsignupButtonPane.add(saveTButton,1,5,2,1);



    //TEACHER LOGIN SCENE

    //Login title  
    AnchorPane TloginPane = new AnchorPane();
    Tlogin = new Image(getClass().getResourceAsStream("Tlogin.png"));
    ImageView Tlogintitleview = new ImageView();
    Tlogintitleview.setImage(Tlogin);
    TloginPane.getChildren().add(Tlogintitleview);
    ImageView Tlogintitleapp = (ImageView) TloginPane.getChildren().get(0);
    Tlogintitleapp.setX(130);
    Tlogintitleapp.setY(10);


    //top/right/bottom/left
    //Login buttons panel
    TloginButtonPane = new GridPane();
    TloginButtonPane.setHgap(100); 
    TloginButtonPane.setVgap(25); 
    TloginButtonPane.setPadding(new Insets(200, 10, 0, 10));


    userTextFieldT = new TextField("User Name");
    userTextFieldT.setPrefWidth(400.0);
    userTextFieldT.setPrefHeight(60.0);
    userTextFieldT.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");

    TloginButtonPane.add(userTextFieldT,2,1);



    passwordTextFieldT = new PasswordField();
    passwordTextFieldT.setText("Password");
    passwordTextFieldT.setPrefWidth(400.0);
    passwordTextFieldT.setPrefHeight(60.0);
    passwordTextFieldT.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");

    TloginButtonPane.add(passwordTextFieldT,2,2);


    TloginButton = new Button("LOGIN");
    TloginButton.addEventHandler(ActionEvent.ACTION, (e)-> {

        try
        {
            String query = "select * from TeachersInfo where username=? and password=? ";
            PreparedStatement pst = connectionUsers.prepareStatement(query);
            //First question mark = 1, second = 2, etc.
            pst.setString(1,userTextFieldT.getText());
            pst.setString(2,passwordTextFieldT.getText());

            //Exescute the query
            ResultSet rs = pst.executeQuery();
            int count = 0;
            while(rs.next())
            {
                count = count+1;
            }
            if(count == 1)
            {
                gui.primaryStage.setScene(sceneAddQ);
            }
            else if(count >1)
            {

            }
            else
            {
                TloginProblemLabel.setText("!!User name or password incorrect!!");
                gui.primaryStage.setScene(sceneTLogIn);
            }

            //after executing the query this lines will close the connection with the database
            rs.close();
            pst.close();
        }
        catch(Exception a)
        {
            System.out.println(a);
        }

    });     
    TloginButton.setPrefWidth(400.0);
    TloginButton.setPrefHeight(60.0);
    TloginButton.setStyle("-fx-font: 40 timesnewroman; -fx-base: #AE3522");

    TloginButtonPane.add(TloginButton,2,3);


    TloginProblemLabel = new Label();
    TloginProblemLabel.setPrefWidth(600.0);
    TloginProblemLabel.setPrefHeight(50.0);
    TloginProblemLabel.setStyle("-fx-font: 21 timesnewroman; -fx-base: #AE3522; -fx-text-fill: red;");

    TloginButtonPane.add(TloginProblemLabel,1,4,2,1);



    backButton = new Button("BACK");
    backButton.setOnAction(e -> gui.primaryStage.setScene(gui.sceneChooseUser));
    backButton.setPrefWidth(140.0);
    backButton.setPrefHeight(50.0);
    backButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522;");

    TloginButtonPane.add(backButton,1,5);   

    TsignupButton = new Button("SIGN UP");
    TsignupButton.setOnAction(e -> gui.primaryStage.setScene(sceneTSignUp));
    TsignupButton.setPrefWidth(180.0);
    TsignupButton.setPrefHeight(50.0);
    TsignupButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");

    TloginButtonPane.add(TsignupButton,3,5);



     //ADD QUESTIONS TO THE DATABASE


    //Own questions title  
    AnchorPane addQpane = new AnchorPane();
    addQuestions = new Image(getClass().getResourceAsStream("addQuestions.png"));
    ImageView addQtitleview = new ImageView();
    addQtitleview.setImage(addQuestions);
    addQpane.getChildren().add(addQtitleview);
    ImageView addQtitleapp = (ImageView) addQpane.getChildren().get(0);
    addQtitleapp.setX(90);
    addQtitleapp.setY(10);


    //Own questions buttons
    addQButtonPane = new GridPane();
    addQButtonPane.setHgap(10); 
    addQButtonPane.setVgap(20); 
    addQButtonPane.setPadding(new Insets(10, 100, 0, 100));
    addQButtonPane.setStyle("-fx-background-color: #FECB6E;");



    subjectLabel = new Label("Subject:");
    subjectLabel.setPrefWidth(300.0);
    subjectLabel.setPrefHeight(70.0);
    subjectLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");

    addQButtonPane.add(subjectLabel,1,1);



    //Putting the radio buttons in a toggleGroup so that they are mutually exclusive.
    ToggleGroup groupSubject = new ToggleGroup();

    mathRB = new RadioButton("Math");
    mathRB.setPrefWidth(200.0);
    mathRB.setPrefHeight(40.0);
    mathRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
    mathRB.setToggleGroup(groupSubject);

    addQButtonPane.add(mathRB,1,2);


    historyRB = new RadioButton("History");
    historyRB.setPrefWidth(200.0);
    historyRB.setPrefHeight(40.0);
    historyRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
    historyRB.setToggleGroup(groupSubject);

    addQButtonPane.add(historyRB,2,2);


    spanishRB = new RadioButton("Spanish");
    spanishRB.setPrefWidth(200.0);
    spanishRB.setPrefHeight(40.0);
    spanishRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
    spanishRB.setToggleGroup(groupSubject);

    addQButtonPane.add(spanishRB,3,2);


    physicsRB = new RadioButton("Physics");
    physicsRB.setPrefWidth(200.0);
    physicsRB.setPrefHeight(40.0);
    physicsRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
    physicsRB.setToggleGroup(groupSubject);

    addQButtonPane.add(physicsRB,1,3);


    sciencesRB = new RadioButton("Sciences");
    sciencesRB.setPrefWidth(200.0);
    sciencesRB.setPrefHeight(40.0);
    sciencesRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
    sciencesRB.setToggleGroup(groupSubject);

    addQButtonPane.add(sciencesRB,2,3);


    geographyRB = new RadioButton("Geography");
    geographyRB.setPrefWidth(200.0);
    geographyRB.setPrefHeight(40.0);
    geographyRB.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
    geographyRB.setToggleGroup(groupSubject);

    addQButtonPane.add(geographyRB,3,3);



    mathRB.setUserData("Math");
    historyRB.setUserData("History");
    spanishRB.setUserData("Spanish");
    physicsRB.setUserData("Physics");
    sciencesRB.setUserData("Sciences");
    geographyRB.setUserData("Geography");


    groupSubject.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
        public void changed(ObservableValue<? extends Toggle> ov,
            Toggle toggle, Toggle new_toggle)
            {
                if (new_toggle != null)
                {
                    textSubjectQ =  (String) groupSubject.getSelectedToggle().getUserData();
                }

            }
    });




    typeQLabel = new Label("Type of Question:");
    typeQLabel.setPrefWidth(350.0);
    typeQLabel.setPrefHeight(70.0);
    typeQLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");

    addQButtonPane.add(typeQLabel,1,5);

    //Putting the radio buttons in a toggleGroup so that they are mutually exclusive.
    ToggleGroup groupTypeQ = new ToggleGroup();

    typeQ1 = new RadioButton("Connect with Arrows");
    typeQ1.setPrefWidth(350.0);
    typeQ1.setPrefHeight(40.0);
    typeQ1.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
    typeQ1.setToggleGroup(groupTypeQ);

    addQButtonPane.add(typeQ1,1,6);



    typeQ2 = new RadioButton("Choose Answer");
    typeQ2.setPrefWidth(350.0);
    typeQ2.setPrefHeight(40.0);
    typeQ2.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
    typeQ2.setToggleGroup(groupTypeQ);

    addQButtonPane.add(typeQ2,2,6);



    typeQ3 = new RadioButton("Introduce Answer");
    typeQ3.setPrefWidth(250.0);
    typeQ3.setPrefHeight(40.0);
    typeQ3.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;-fx-text-fill: black;");
    typeQ3.setToggleGroup(groupTypeQ);

    addQButtonPane.add(typeQ3,3,6);


    typeQ1.setUserData("Connect with Arrows");
    typeQ2.setUserData("Choose Answer");
    typeQ3.setUserData("Introduce Answer");


    groupTypeQ.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
        public void changed(ObservableValue<? extends Toggle> ov,
            Toggle toggle, Toggle new_toggle)
            {
                if (new_toggle != null)
                {
                    textTypeQ =  (String) groupTypeQ.getSelectedToggle().getUserData();
                }

            }
    });



    levelLabel = new Label("Level:");
    levelLabel.setPrefWidth(220.0);
    levelLabel.setPrefHeight(70.0);
    levelLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");

    addQButtonPane.add(levelLabel,1,8);



    ToggleGroup groupLevelQ = new ToggleGroup();

    easyLevelButton = new ToggleButton("EASY");
    //easyLevelButton.setOnAction(e -> primaryStage.setScene(sceneOwnQ));
    easyLevelButton.setPrefWidth(150.0);
    easyLevelButton.setPrefHeight(50.0);
    easyLevelButton.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;");
    easyLevelButton.setToggleGroup(groupLevelQ);

    addQButtonPane.add(easyLevelButton,1,9);


    mediumLevelButton = new ToggleButton("MEDIUM");
    //mediumLevelButton.setOnAction(e -> primaryStage.setScene(sceneOwnQ));
    mediumLevelButton.setPrefWidth(150.0);
    mediumLevelButton.setPrefHeight(50.0);
    mediumLevelButton.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;");
    mediumLevelButton.setToggleGroup(groupLevelQ);

    addQButtonPane.add(mediumLevelButton,2,9);



    highLevelButton = new ToggleButton("HIGH");
    //highLevelButton.setOnAction(e -> primaryStage.setScene(sceneOwnQ));
    highLevelButton.setPrefWidth(150.0);
    highLevelButton.setPrefHeight(50.0);
    highLevelButton.setStyle("-fx-font: 20 timesnewroman; -fx-base: #AE3522;");
    highLevelButton.setToggleGroup(groupLevelQ);

    addQButtonPane.add(highLevelButton,3,9);


    easyLevelButton.setUserData("Easy");
    mediumLevelButton.setUserData("Medium");
    highLevelButton.setUserData("High");


    groupLevelQ.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
        public void changed(ObservableValue<? extends Toggle> ov,
            Toggle toggle, Toggle new_toggle)
            {
                if (new_toggle != null)
                {
                    textLevelQ =  (String) groupLevelQ.getSelectedToggle().getUserData();
                }

            }
    });




    speedLabel = new Label("Speed:");
    speedLabel.setPrefWidth(220.0);
    speedLabel.setPrefHeight(70.0);
    speedLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");

    addQButtonPane.add(speedLabel,1,11);



    speedTextField = new TextField("minutes");
    speedTextField.setPrefWidth(50.0);
    speedTextField.setPrefHeight(50.0);
    speedTextField.setStyle("-fx-font: 20 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");

    // page.add(Node, colIndex, rowIndex, colSpan, rowSpan):
    addQButtonPane.add(speedTextField, 2, 11);





    contentQLabel = new Label("Content of the Question:");
    contentQLabel.setPrefWidth(600.0);
    contentQLabel.setPrefHeight(50.0);
    contentQLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");

    //This makes the label to be occupying more than one column so the other smaller buttons don't move.
    addQButtonPane.add(contentQLabel, 1, 13, 2, 1);



    contentQTextField = new TextField();
    contentQTextField.setPrefWidth(800.0);
    contentQTextField.setPrefHeight(50.0);
    contentQTextField.setStyle("-fx-font: 20 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");

    // page.add(Node, colIndex, rowIndex, colSpan, rowSpan):
    addQButtonPane.add(contentQTextField, 1, 14, 3, 1);



    answerQLabel = new Label("Answer of the Question:");
    answerQLabel.setPrefWidth(600.0);
    answerQLabel.setPrefHeight(50.0);
    answerQLabel.setStyle("-fx-font: 30 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");

    //This makes the label to be occupying more than one column so the other smaller buttons don't move.
    addQButtonPane.add(answerQLabel, 1, 16, 2, 1);



    answerQTextField = new TextField();
    answerQTextField.setPrefWidth(800.0);
    answerQTextField.setPrefHeight(50.0);
    answerQTextField.setStyle("-fx-font: 20 timesnewroman; -fx-base: #190707;-fx-text-fill: black;");

    // page.add(Node, colIndex, rowIndex, colSpan, rowSpan):
    addQButtonPane.add(answerQTextField, 1, 17, 3, 1);



    doneButton = new Button("DONE");
    doneButton.addEventHandler(ActionEvent.ACTION, (e)-> {
        gui.primaryStage.setScene(gui.sceneChooseUser);

        problemLabel.setText(null);
    });
    doneButton.setPrefWidth(140.0);
    doneButton.setPrefHeight(50.0);
    doneButton.setStyle("-fx-font: 30 timesnewroman; -fx-base: #AE3522");

    addQButtonPane.add(doneButton,1,21);



    addQButton = new Button("ADD QUESTION");
    //Adding more that one action to a button;
    addQButton.addEventHandler(ActionEvent.ACTION, (e)-> {
        try
        {
            String query = "insert into Questions (Subject,Type,Level,Speed,Question,Answer) values (?,?,?,?,?,?)";
            PreparedStatement pst = connectionQuestions.prepareStatement(query);
            //First question mark = 1, second = 2, etc.
            pst.setString(1,textSubjectQ);
            pst.setString(2,textTypeQ);
            pst.setString(3,textLevelQ);
            //pst.setString(4,textSpeedQ);
            pst.setString(4,speedTextField.getText());
            pst.setString(5,contentQTextField.getText());
            pst.setString(6,answerQTextField.getText());


            pst.execute();

            System.out.println("Data saved");

            //after executing the query this lines will close the connection with the database
            pst.close();

        }
        catch(Exception a)
        {
            System.out.println(a);
        }


        gui.primaryStage.setScene(sceneAddQ);

    });
    addQButton.setPrefWidth(350.0);
    addQButton.setPrefHeight(50.0);
    addQButton.setStyle("-fx-font: 25 timesnewroman; -fx-base: #2EFE64; -fx-text-fill: black;");

    addQButtonPane.add(addQButton,3,21);



    problemLabel = new Label();
    problemLabel.setPrefWidth(600.0);
    problemLabel.setPrefHeight(50.0);
    problemLabel.setStyle("-fx-font: 21 timesnewroman; -fx-base: #AE3522; -fx-text-fill: red;");

    addQButtonPane.add(problemLabel,1,22,4,1);


    //Pane to be able to have a scrollbar
    ScrollPane sp = new ScrollPane(); 
    sp.setFitToWidth(true);

    ScrollBar s1 = new ScrollBar();
    s1.setOrientation(Orientation.VERTICAL);

    sp.setContent(s1);
    sp.setContent(addQButtonPane);
    sp.setStyle("-fx-background-color: #FECB6E;");


    //Makes possible to have two panes in the same scene/layout
    HBox hBoxAddQ = new HBox();
    hBoxAddQ.setSpacing(10.0); 
    hBoxAddQ.setPadding(new Insets(140,10,50,10));
    hBoxAddQ.getChildren().addAll(addQButtonPane, sp);




    //Add things to the teacher login layout
    layoutTLogIn.getChildren().add(TloginPane);
    layoutTLogIn.getChildren().add(TloginButtonPane);

    //Add things to the teacher signup layout
    layoutTSignUp.getChildren().add(TsignupPane);
    layoutTSignUp.getChildren().add(TsignupButtonPane);

    //Add things to the add questions to database by the teacher
    layoutAddQ.getChildren().add(addQpane);
    layoutAddQ.getChildren().add(hBoxAddQ);


}


  }

The student class looks basically the same and then I have the classes to connect the databases.One of them with the questions database and the other one with the users database. They both look the same. For example, one of the two looks like this:

DATABASE CONNECTION

 public class questionssqliteConnection
 {
     Connection conn = null;
public static Connection dbConnector()
{
    try
    {
        Class.forName("org.sqlite.JDBC");
        Connection conn = DriverManager.getConnection("jdbc:sqlite:/Users/cachuti/Documents/Questions.sqlite");
        System.out.println("Connection");
        return conn;
    }
    catch(Exception e)
    {
        System.out.println(e);
        return null;
    }
   }
  }

So, as I said, before I had one big class with all the infromation that now is in GUI, Teacher, and Student and it worked. I really dont know what is the problem so i would really appreciate the help. Thank you so much in advance.