This is a very simple example of helping classmates write, because I have no mobile devices in hand, and what simulator will not be used at that time. .
Therefore, there is no administration in the successful debugging of this level. The database is used by SQL Anywhere, I feel that this is not bad. Because I have never been studied before, I think this is convenient. Don't buy melon again, how to use SQL Anywhere to speak in detail, I also have its Chinese documentation to study. If the friend wants to be lazy, I don't want to find myself.
Sans_reason@hotmail.com I sent it to you. Ha ha
/ *
* If you deploy it to the WindowsCe device, you copy the jul9.dll and jul9_zh.jar yourself.
* Device should install DJEODE
* Establish Test.lnk
* 18 # "/ Memory Card / Insignia Solutions Jeoderuntime / evm.exe"
* -Djeode.evm.console.local.keep = TRUE
* -Djeode.evm.console.local.paging = True
* -Djul.library.dir = / UltraLite / LIB
* -cp /ultralite/tutorial;/ultralite/lib/jul9_zh.jar
* Customer
* /
/ **
* @Author Liyou
*
*
* /
Import iAnywhere.native_ultralite. *;
Import java.sql.sqlexception;
Public class customer {
Static connect conn;
Public static void main (string args []) {
Try {
Customer Cust = New Customer ();
Cust.insert ();
Cust.select ();
CONN.CLOSE ();
} catch (sqlexception e) {
E.PrintStackTrace ();
}
}
Public Customer () throws sqlexception {
DatabaseManager dbmgr = new databaseManager ();
/ *
* UltraLite default drip database username and password. . . How can I change I don't know, I don't have this thing.
* /
String Parms = "UID = DBA"
"; PWD = SQL"
"; file_name = f: //j2me/tutcuStomer.udb"
"; schema_file = f: //j2me/tutcuStomer.uSM"
"; CE_FILE = // UltraLite // Tutorial // Tutcustomer.udb"
"; CE_SCHEMA = // UltraLite // Tutorial // Tutcustomer.usm";
/ *
* Add two items to this line if deployed to the WindowsCe device
* CE_FILE = // UltraLite // Tutorial // Tutcustomer.udb
* CE_SCHEMA = // UltraLite // Tutorial // Tutcustomer.USM
*
* There should be no effect on the two lines in the desktop! Pay attention!
* /
Try {
CONN = DBMGR.OpenConnection (PARMS);
System.out.println (
"Connect to Database TUTCUSTOMER!");
} catch (sqlexception econn) {
IF (eConn.GeterrorCode () == SQLCODE.SQLE_ULTRALITE_DATABASE_NOT_FOUND) {// Determined SQL error code, if there is no database file, create the drip mode creation
CONN = dbmgr.createdatabase (PARMS);
System.out.println ("" has created a database according to the UltraLite mode provided ");
} else {
Econn.printStackTrace ();
}
}
}
Private void insert () throws sqlexception {
Table t = conn.gettable ("Customer");
T.Open ();
Short id = t.schema.getColumnId ("id");
Short fname = t.schema.getColumnId ("fnamee");
Short lname = t.schema.getColumnid ("lnamee");
IF (t.GetrowCount () == 0) {
/ / Determine if there is data in the database, there is no longer added, not adding. . .
/ / Don't tell me, you don't know how to change this place.
T.insertbegin ();
T.SetString (FName, "Li");
T.SetString (LName, "you");
T.insert ();
CONN.COMMIT ();
System.out.println ("Add data to the database!");
} else {
System.out.println ("There is already a data in the database!");
}
t.close ();
}
Private void select () throws sqlexception {
Table t = conn.gettable ("Customer");
T.Open ();
Short id = t.schema.getColumnId ("id");
Short fname = t.schema.getColumnId ("fnamee");
Short lname = t.schema.getColumnid ("lnamee");
T.MoveBeForefirst ();
While (T.MOVENEXT ()) {
System.out.println (
"ID =" T.Getint (ID)
", Name =" T.getstring (FNAME)
" T.getstring (lname)
"/ n Hahaha, success! Your kid came back asked me to eat! Help you do a lot of things!");
}
t.close ();
}
}