In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to read data from SQL database". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Perform query operation
To perform the operation, use the database.transaction () function:
Var db = openDatabase ('mydb',' 1.0, 'Test DB', 2 * 1024 * 1024)
Db.transaction (function (tx) {
Tx.executeSql ('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)')
});
The above statement, when executed, creates a table named LOGS in the 'mydb' database.
Insert data
After executing the above create table statement, we can insert some data:
Var db = openDatabase ('mydb',' 1.0, 'Test DB', 2 * 1024 * 1024)
Db.transaction (function (tx) {
Tx.executeSql ('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)')
Tx.executeSql ('INSERT INTO LOGS (id, log) VALUES (1, "Rookie tutorial"))
Tx.executeSql ('INSERT INTO LOGS (id, log) VALUES (2, "www.runoob.com"))
});
We can also use dynamic values to insert data:
Var db = openDatabase ('mydb',' 1.0, 'Test DB', 2 * 1024 * 1024)
Db.transaction (function (tx) {
Tx.executeSql ('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)')
Tx.executeSql ('INSERT INTO LOGS (id,log) VALUES', [e_id, e_log])
});
E_id and e_log in the instance are external variables, and executeSql maps each entry in the array parameter to "?".
Read data
The following example shows how to read data that already exists in the database:
Var db = openDatabase ('mydb',' 1.0, 'Test DB', 2 * 1024 * 1024)
Db.transaction (function (tx) {
Tx.executeSql ('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)')
Tx.executeSql ('INSERT INTO LOGS (id, log) VALUES (1, "Rookie tutorial"))
Tx.executeSql ('INSERT INTO LOGS (id, log) VALUES (2, "www.runoob.com"))
});
Db.transaction (function (tx) {
Tx.executeSql ('SELECT * FROM LOGS', [], function (tx, results) {
Var len = results.rows.length, I
Msg = "
Number of query records: "+ len +"
"
Document.querySelector ('# status') [xss_clean] + = msg
For (I = 0; I < len; iTunes +) {
Alert (results.rows.item (I) .log)
}
}, null)
});
This is the end of the content of "how to read data from SQL database". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.