如何sql查询只在android上插入一次

时间:2017-02-06 00:55:05

标签: android sql-server

我只想在插入sql查询时使用A表。

插入查询前的

。如果我的A表有1条记录。执行更新1记录。

我的A表有0条记录。插入查询。

我知道只使用插入查询。

public class compareInsert extends Thread {

    private Connection mConnection = null;
    private Statement mStatement = null;

    @Override
    public void run() {
       super.run();

       Looper.prepare();
       setDB();
       Looper.loop();
    } 

    public void setDB() {
          mConnection = DBconnect.connectJDBC(); // DB Connect.

          try {
              mStatement = mConnection.createStatement();
              mStatement.executeQuery("use be");

              String insertq = "insert into A"
                       + "(name, old, num)"
                       + "values"
                       + "(?, ?, ?);
             PreparedStatement statement = mConnect.prepareStatement(insertq);
             statement.setString(1, "hyunwook");
             statement.setString(2, "17");
             statement.setString(3, "2732");

             int ret = statement.executeUpdate();
             if (ret > 0) {
                Log.d(TAG, "SUCCESS");
             } else {
                Log.d(TAG, "failed");
             }
          } catch (Exception e) {
               e.printStackTrace();
          } finally {
               try {
                    mConnection.close();
               } catch (Exception e) {
               }
          }
      }
   }

此源是插入查询代码。 但应用程序启动,始终插入查询。

请帮帮我

感谢。

0 个答案:

没有答案