日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)OceanBase教程:OceanBaseConnector/J更改數(shù)據(jù)庫

OceanBase Connector/J 支持 DML 操作和 DDL 操作來更改數(shù)據(jù)庫。

DML 操作

要執(zhí)行數(shù)據(jù)操作語言(DML)的 INSERT 或 UPDATE 操作,可以創(chuàng)建一個 Statement 對象或 PreparedStatement 對象。可以使用 PreparedStatement 對象運行帶有輸入?yún)?shù)集的語句。Connection 對象的 prepareStatement 方法可以定義一條語句并采用變量綁定參數(shù),返回帶有語句定義的 PreparedStatement 對象。

PreparedStatement 對象使用 setXXX 方法將數(shù)據(jù)綁定到準備發(fā)送到數(shù)據(jù)庫的語句。

示例:使用 PreparedStatement 執(zhí)行 INSERT 操作將兩行數(shù)據(jù)添加到 customers 表中。


PreparedStatement ps = null;
try{
    ps = conn.prepareStatement ("insert into customers (customerID, name) values (?, ?)");

    ps.setInt (1, 150);              // 第一個? 對應 customerID
    ps.setString (2, "Adam");   // 第二個? 對應 name

    ps.execute ();

    ps.setInt (1, 207);           
    ps.setString (2, "Alice");   
    ps.execute ();
}

finally{
     if(ps!=null)
     ps.close();
}

DDL 操作

要執(zhí)行數(shù)據(jù)定義語言(DDL)操作,可以創(chuàng)建一個 Statement 對象或 PreparedStatement 對象。

示例:使用 Statement 對象在數(shù)據(jù)庫中創(chuàng)建表。


//創(chuàng)建表 customers 以及 customerID 和 name 列
String query;
Statement st=null;

try{
    query="create table customers " +
          "(customerID int, " +
          "name varchar(50))";
    st = conn.createStatement();
    st.executeUpdate(query);
    }
finally{
     //關(guān)閉 Statement
     st.close();
    }

如果涉及重新執(zhí)行 DDL 操作,那么在重新執(zhí)行該語句之前,必須重新進行準備。

示例:在重新執(zhí)行之前準備 DDL 語句。


PreparedStatement ps = null;
PreparedStatement ts = null;
try{
    ps = conn.prepareStatement ("insert into customers(customerID, name) values (?, ?)");
 
    // 添加新顧客 Adam,編號150
    ps.setInt (1, 150);          // 第一個? 對應 customerID
    ps.setString (2, "Adam");   // 第二個? 對應 name
    // 插入數(shù)據(jù)
    ps.execute ();
    
    ts = conn.prepareStatement("truncate table customers"); 
    ts.executeUpdate();
 
 
    // 添加新顧客 Alice,編號 207
    ps.setInt (1, 207);           // 第一個? 對應 customerID
    ps.setString (2, "Alice");   // 第二個? 對應 name
    // 插入數(shù)據(jù)
    ps.execute ();
 
    ts.close();
    ts = conn.prepareStatement("truncate table customers"); 
    ts.executeUpdate();
    }
finally{
     if(ps!=null)
     // 關(guān)閉 Statement
     ps.close();
}

網(wǎng)站標題:創(chuàng)新互聯(lián)OceanBase教程:OceanBaseConnector/J更改數(shù)據(jù)庫
本文鏈接:http://www.5511xx.com/article/dpdessd.html