java sql insert

前端 未结 4 879
[愿得一人]
[愿得一人] 2021-01-05 07:17

I got a table with 4 fields:

id, int(11), auto increament email, varchar(32) pass, varchar(32) date_created, date

My question

相关标签:
4条回答
  • 2021-01-05 07:39

    In SQL you can specify which columns you want to set in the INSERT statement:

    INSERT INTO table_name(email, pass, date_created) VALUES(?, ?, ?)
    
    0 讨论(0)
  • 2021-01-05 07:39

    You can insert in the format

    INSERT INTO YourTable (Your Columns) VALUES (Your Values)
    

    So for e.g.

    INSERT INTO Test_Table (email, pass, data_created) VALUES ('john@blah.com', 'pass', to_date(string, format))
    
    0 讨论(0)
  • 2021-01-05 07:52

    First of all, I hope you're using PreparedStatements.

    Assuming you have a Connection object named conn and two strings email and password...

    PreparedStatement stmt = conn.prepareStatement("INSERT INTO table_name(email, pass, date_created) VALUES (?, ?, ?)");
    
    stmt.setString(1, email);
    stmt.setString(2, password);
    stmt.setDate(3, new Date());
    
    stmt.executeUpdate();
    
    0 讨论(0)
  • 2021-01-05 07:53

    Using parameters-tsql; (better to pass values in parameters rather than as strings)

    Insert into [YourTableName] (email, pass, date_created) 
    values (@email, @pass, @date_created)
    
    0 讨论(0)
提交回复
热议问题