This is a very, very simple example of writing a classmate, because I don't have a mobile device on hand, and I don't use any simulators at that time. , so the success of debugging at this level is out of control. The database is SQL Anywhere, and it feels good. Because it has not been studied before, so I think this thing convenient. I will not buy the melon again how to use SQL anywhere in detail, I also under its Chinese document to study. If the guy wants to be lazy and don't want to find his own, add my sans_reason@hotmail.com I sent you. Oh
/*
* If deployed to WINDOWSCE devices, copy Jul9.dll and Jul9_zh.jar themselves.
* Equipment should be installed 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 Connection 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 database username and password ... How to change don't know, I won't this thing also did not study
*/
String parms = "UID=DBA"
+ ";p wd=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";
/*
* If you are deploying to a WINDOWSCE device, add two lines to this line
* CE_FILE=\\ULTRALITE\\TUTORIAL\\TUTCUSTOMER.UDB
* CE_SCHEMA=\\ULTRALITE\\TUTORIAL\\TUTCUSTOMER.USM
*
* In the desktop should be the system of these two lines have no effect drop! Watch yourself!
*/
try {
conn = Dbmgr.openconnection (parms);
System.out.println (
"Connect to Database tutcustomer!");
}catch (SQLException econn) {
if (Econn.geterrorcode () ==sqlcode.sqle_ultralite_database_not_found) {
To determine the SQL error code, if it does not have the database file, create it according to the drop pattern provided
conn = Dbmgr.createdatabase (parms);
SYSTEM.OUT.PRINTLN ("The database has been created based on the provided Ultralite schema");
}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) {
To determine whether there is data inside the database, there is no longer add, no add ...
You 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 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)
+ "hahaha, success!" You boys come back to buy me dinner! Helped you do a lot of these things! ");
}
T.close ();
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.