(1)、在AOT中建立一个class(aTestForDB):
(2)、method main():
static void main(Args args)
{
HelloWorld hw = new HelloWorld();
Str sql="select * from userinfo";
//**********************
//****±äÁ¿µÄÉùÃ÷********
//**********************
int i=0;
str name="XMDDL369";
real r_i=23.789;
boolean b=false;
date d1=11\11\2000;
date d3 = 21\11\1998;
Integer s=90;
int a_i[3];
a_i[0]=1;
//¿¼²é»ù±¾µÄÊý¾ÝÀàÐÍ£¬¼¯ºÏÀàÐÍ
//ÈçºÎͨ¹ýÀàÈ¡µÃÊý¾Ý¿âµÄÁ¬½Ó£¬·µ»Ø¼Ç¼¼¯º
//Òì³£µÄ²¶×½ºÍ´¦Àí
//±äÁ¿µÄ×÷ÓÃÓò
//int a_j[3]={1,2,3};
//*********************
print hw.sayHello()+" XMDDL369";
while(i<10){
print i;
i++;
}
print name;
print r_i;
//print any2str("90.9")+name;
if(b==true)
print "b is true";
else
print "b is not true";
print d3;
print dayofmth(d3);
print dayofwk(d3);
print dayofyr(d3);
print s;
hw.sayWorld();
try
{
print i/0.9;
}
catch (exception::error)
{
print "±» 0 ³ý";
}
///////////////////////////
////////Êý¾Ý¿â²Ù×÷//////////
////////////////////////////
//hw.find();//²éѯÊý¾Ý¿âÈ¡µÃ¼Ç¼
//hw.insert(); //Ôö¡¢É¾¡¢¸Ä¡¢²é£¨CRUD£©
//hw.update();
//hw.delete();
hw.executeBySQL(sql);
}
(2)method find():
void find()
{
UserInfo ui;
select ui where ui.name=="xmddl";
print ui.password;
while select ui
{ //²éѯËùÓеļǼ
print ui.name+" "+ui.Id;
}
}
(3)、method delete():
void delete()
{
Userinfo ui;
ttsbegin;
select forupdate ui where ui.Id=="new";
//ui.Id="new";
ui.delete();
//ui.doDelete();
ttscommit;
}
(4)、method update():
void update()
{
Userinfo ui;
ttsbegin;
select forupdate ui where ui.id=="new";
ui.name="xmddl369";
ui.password="hello new";
ui.update();
ttscommit;
}
(5)、method insert():
void insert()
{
Userinfo ui;
ttsbegin;
ui.Id="new";
ui.name="xmddl";
ui.insert();
ttscommit;
/* ÅúÁ¿¸üÐÂ
MyTable myTable;
RecordInsertList insertList = new RecordInsertList(myTable.TableId, True);
int i;
for ( i = 1; i <= 100; i++ )
{
myTable.value = i;
insertList.add(myTable);
}
insertList.insertDatabase();//<-----this is
*/
}
(6)method executeBySQL():
void executeBySQL(Str sql)
{
Connection con=new Connection();
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
//stmt.executeUpdate(sql);
while(rs.next()){
print "SQL "+rs.getString(1);
}
}