如何在mysql语句中添加变量值?

时间:2018-09-25 13:26:21

标签: java mysql sql

我正在学习使用mysql数据库,现在尝试用文本字段中的文本填充语句。 程序是电话簿,字符串是名称,姓氏和电话号码,必须在文本字段中写入,然后将其添加到要导入数据库的语句中。 所以,现在我有了这个,但是却无法正常工作,因为语句甚至都没有将字符串识别为值。

if("Potvrdi".equals(buttonLabel)) {

            String ime = a.getText();
            String prezime = b.getText();
            String broj = c.getText();

            Connection conn = dc.connect();
            Statement st = (Statement) conn.createStatement(); 
            st.executeUpdate("INSERT INTO imenik VALUES (ime,prezime,broj)");
            conn.close();
            }

1 个答案:

答案 0 :(得分:2)

使用prepare语句,

@section BottomScripts {
 @if (Model.NeedThisScript)
 {
  await Html.RenderPartialAsync("PartialWithYourScripts");
 }
}