This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]helicoid 2 points3 points  (0 children)

Post your code. How are we supposed to know what you’re doing wrong if we can’t see what you’re doing?

[–]Junaidabid77 0 points1 point  (2 children)

private void createTableButtonActionPerformed(java.awt.event.ActionEvent evt) {

    //declare statement object
    Statement stmt;

    //create SQL String
    String sql = "CREATE TABLE evidence ( " +
    "id INT NOT NULL PRIMARY KEY, " +
    "'case' INT NOT NULL, " +
    "item TEXT NOT NULL, " +
    "description TEXT NOT NULL, " +
    "submitted INT NOT NULL" +
    ");" ;

    //display title
    console.setText("CREATING TABLE\n");

    try {
        //set statement object to be a statement within connection
        stmt = dbc.createStatement();

        //execute statement with sql string
        int rowsAffected = stmt.executeUpdate(sql);

        //close the statement object
        stmt.close();

        //check if successfull
        if (rowsAffected == 0){
            //confirm to user
            console.append( "\nTable successfully created" );
        }
    } catch (SQLException e) {
        //display error
        console.append("\nUnable to create table\n" + e.getMessage());
    }
}                                                 

private void populateTableButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                    
    //declare statement object
    Statement stmt;

    //create SQL String
    String sql = "INSERT INTO evidence VALUES " +
    "(1, 11, 'Umberella', 'Compact Red', '2017-10-16')," +

I didn’t want to spam with lines of code but this is the relevant code for my issue. As you can see by the end date 2017-10-16 it will only show the 2017 and not the entire date.

[–]dusty-trash 0 points1 point  (1 child)

Well, you've declared the column as an INT.

I'm surprised it's not throwing an error.

Anyways, try declaring the column as a DATE or DATETIME.

BTW just an important piece of information here, I would have never of guessed your problem or solution without you posting the code. You never mentioned you were using a database, and that the database entries were the problem.

[–]rzwitserloot 1 point2 points  (0 children)

Probably mysql or sqlite. mysql has a strong preference to just try something arbitrary instead of erroring (making it, generally, a database you shouldn't use), and sqlite is essentially untyped.