Reshma
Reshma

Reputation: 904

Inserting data into MY SQL database

I am trying to insert values retrieved from dictionary into Database but unable to do so, my insert statement is as follows,

    String command="INSERT INTO TABLE1(elog_r)VALUES(@rV where id=@value);";

    where value of rV is

    rV=dict.get("VOLTAGE-VR");

In ASP.NET we can write as

command.Parameters.AddWithValue("@rV", rV);

I want the solution for the same in JAVA.

Upvotes: 0

Views: 165

Answers (1)

Juned Ahsan
Juned Ahsan

Reputation: 68715

This is the sample from mykong website, which you can give you some hint about using the java JDBC to insert data in a table:

String insertTableSQL = "INSERT INTO DBUSER"
        + "(USER_ID, USERNAME, CREATED_BY, CREATED_DATE) VALUES"
        + "(?,?,?,?)";
PreparedStatement preparedStatement = dbConnection.prepareStatement(insertTableSQL);
preparedStatement.setInt(1, 11);
preparedStatement.setString(2, "mkyong");
preparedStatement.setString(3, "system");
preparedStatement.setTimestamp(4, getCurrentTimeStamp());
// execute insert SQL stetement
preparedStatement .executeUpdate();

You can follow the complete tutorial here:

http://www.mkyong.com/jdbc/jdbc-preparestatement-example-insert-a-record/

Upvotes: 1

Related Questions