read file's data android studio
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm trying to read the script file, I'v putted a filename which is "test.sql". But I got error when I run the code.
Here is the error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.waiku.work2, PID: 3990
android.database.sqlite.SQLiteException: near "Pertama": syntax error (code 1): , while compiling: INSERT INTO `Table1` (name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(near "Pertama": syntax error (code 1): , while compiling: INSERT INTO `Table1` (name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');)
#################################################################
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at com.example.waiku.work2.MainActivity$3.onClick(MainActivity.java:100)
This is my code where the error line 100 pointed to the db.execSQL(line);
.
mBtnImport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SQLiteDatabase db = mSQLiteHelper.getWritableDatabase();
try {
String filename = "test.sql";
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, filename);
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
if (line.trim().length() > 0) {
db.execSQL(line);
db.close();
}
}
Toast.makeText(getApplicationContext(), "Upgrade complete.", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
new upgradeDB().execute("", "", "");
}
});
May I know what is the error?
java android sqlite
|
show 2 more comments
I'm trying to read the script file, I'v putted a filename which is "test.sql". But I got error when I run the code.
Here is the error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.waiku.work2, PID: 3990
android.database.sqlite.SQLiteException: near "Pertama": syntax error (code 1): , while compiling: INSERT INTO `Table1` (name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(near "Pertama": syntax error (code 1): , while compiling: INSERT INTO `Table1` (name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');)
#################################################################
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at com.example.waiku.work2.MainActivity$3.onClick(MainActivity.java:100)
This is my code where the error line 100 pointed to the db.execSQL(line);
.
mBtnImport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SQLiteDatabase db = mSQLiteHelper.getWritableDatabase();
try {
String filename = "test.sql";
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, filename);
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
if (line.trim().length() > 0) {
db.execSQL(line);
db.close();
}
}
Toast.makeText(getApplicationContext(), "Upgrade complete.", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
new upgradeDB().execute("", "", "");
}
});
May I know what is the error?
java android sqlite
2
You need to quote string values in SQL, e.g.'Taman Pertama'
.
– Henry
Nov 23 '18 at 8:23
Sorry, What do you mean? I don't quite understand... @Henry
– Leon Zaii
Nov 23 '18 at 8:43
There are SQL syntax errors in your filetest.sql
.
– Henry
Nov 23 '18 at 8:45
I changed'Taman Pertama'
toNULL
. Also got this error @Henry
– Leon Zaii
Nov 23 '18 at 8:48
your SQL query is invalid. There is no problem with reading file.
– Vladyslav Matviienko
Nov 23 '18 at 8:53
|
show 2 more comments
I'm trying to read the script file, I'v putted a filename which is "test.sql". But I got error when I run the code.
Here is the error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.waiku.work2, PID: 3990
android.database.sqlite.SQLiteException: near "Pertama": syntax error (code 1): , while compiling: INSERT INTO `Table1` (name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(near "Pertama": syntax error (code 1): , while compiling: INSERT INTO `Table1` (name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');)
#################################################################
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at com.example.waiku.work2.MainActivity$3.onClick(MainActivity.java:100)
This is my code where the error line 100 pointed to the db.execSQL(line);
.
mBtnImport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SQLiteDatabase db = mSQLiteHelper.getWritableDatabase();
try {
String filename = "test.sql";
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, filename);
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
if (line.trim().length() > 0) {
db.execSQL(line);
db.close();
}
}
Toast.makeText(getApplicationContext(), "Upgrade complete.", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
new upgradeDB().execute("", "", "");
}
});
May I know what is the error?
java android sqlite
I'm trying to read the script file, I'v putted a filename which is "test.sql". But I got error when I run the code.
Here is the error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.waiku.work2, PID: 3990
android.database.sqlite.SQLiteException: near "Pertama": syntax error (code 1): , while compiling: INSERT INTO `Table1` (name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(near "Pertama": syntax error (code 1): , while compiling: INSERT INTO `Table1` (name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');)
#################################################################
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at com.example.waiku.work2.MainActivity$3.onClick(MainActivity.java:100)
This is my code where the error line 100 pointed to the db.execSQL(line);
.
mBtnImport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SQLiteDatabase db = mSQLiteHelper.getWritableDatabase();
try {
String filename = "test.sql";
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, filename);
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
if (line.trim().length() > 0) {
db.execSQL(line);
db.close();
}
}
Toast.makeText(getApplicationContext(), "Upgrade complete.", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
new upgradeDB().execute("", "", "");
}
});
May I know what is the error?
java android sqlite
java android sqlite
edited Nov 24 '18 at 16:03
John Joe
5,47232565
5,47232565
asked Nov 23 '18 at 8:20
Leon ZaiiLeon Zaii
8310
8310
2
You need to quote string values in SQL, e.g.'Taman Pertama'
.
– Henry
Nov 23 '18 at 8:23
Sorry, What do you mean? I don't quite understand... @Henry
– Leon Zaii
Nov 23 '18 at 8:43
There are SQL syntax errors in your filetest.sql
.
– Henry
Nov 23 '18 at 8:45
I changed'Taman Pertama'
toNULL
. Also got this error @Henry
– Leon Zaii
Nov 23 '18 at 8:48
your SQL query is invalid. There is no problem with reading file.
– Vladyslav Matviienko
Nov 23 '18 at 8:53
|
show 2 more comments
2
You need to quote string values in SQL, e.g.'Taman Pertama'
.
– Henry
Nov 23 '18 at 8:23
Sorry, What do you mean? I don't quite understand... @Henry
– Leon Zaii
Nov 23 '18 at 8:43
There are SQL syntax errors in your filetest.sql
.
– Henry
Nov 23 '18 at 8:45
I changed'Taman Pertama'
toNULL
. Also got this error @Henry
– Leon Zaii
Nov 23 '18 at 8:48
your SQL query is invalid. There is no problem with reading file.
– Vladyslav Matviienko
Nov 23 '18 at 8:53
2
2
You need to quote string values in SQL, e.g.
'Taman Pertama'
.– Henry
Nov 23 '18 at 8:23
You need to quote string values in SQL, e.g.
'Taman Pertama'
.– Henry
Nov 23 '18 at 8:23
Sorry, What do you mean? I don't quite understand... @Henry
– Leon Zaii
Nov 23 '18 at 8:43
Sorry, What do you mean? I don't quite understand... @Henry
– Leon Zaii
Nov 23 '18 at 8:43
There are SQL syntax errors in your file
test.sql
.– Henry
Nov 23 '18 at 8:45
There are SQL syntax errors in your file
test.sql
.– Henry
Nov 23 '18 at 8:45
I changed
'Taman Pertama'
to NULL
. Also got this error @Henry– Leon Zaii
Nov 23 '18 at 8:48
I changed
'Taman Pertama'
to NULL
. Also got this error @Henry– Leon Zaii
Nov 23 '18 at 8:48
your SQL query is invalid. There is no problem with reading file.
– Vladyslav Matviienko
Nov 23 '18 at 8:53
your SQL query is invalid. There is no problem with reading file.
– Vladyslav Matviienko
Nov 23 '18 at 8:53
|
show 2 more comments
1 Answer
1
active
oldest
votes
android.database.sqlite.SQLiteException: near "Pertama": syntax error
(code 1): , while compiling: INSERT INTOTable1
(name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');
Is saying that you have a syntax error. Strings/Text should be enclosed in single quotes.
So need need to use something like
INSERT INTO Table1 (name,address,phone,id) VALUES ('WK','Taman Pertama',NULL,4);
i.e. WK and Taman Pertama need to be enclosed in quotes the number doesn't need to be.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442929%2fread-files-data-android-studio%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
android.database.sqlite.SQLiteException: near "Pertama": syntax error
(code 1): , while compiling: INSERT INTOTable1
(name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');
Is saying that you have a syntax error. Strings/Text should be enclosed in single quotes.
So need need to use something like
INSERT INTO Table1 (name,address,phone,id) VALUES ('WK','Taman Pertama',NULL,4);
i.e. WK and Taman Pertama need to be enclosed in quotes the number doesn't need to be.
add a comment |
android.database.sqlite.SQLiteException: near "Pertama": syntax error
(code 1): , while compiling: INSERT INTOTable1
(name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');
Is saying that you have a syntax error. Strings/Text should be enclosed in single quotes.
So need need to use something like
INSERT INTO Table1 (name,address,phone,id) VALUES ('WK','Taman Pertama',NULL,4);
i.e. WK and Taman Pertama need to be enclosed in quotes the number doesn't need to be.
add a comment |
android.database.sqlite.SQLiteException: near "Pertama": syntax error
(code 1): , while compiling: INSERT INTOTable1
(name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');
Is saying that you have a syntax error. Strings/Text should be enclosed in single quotes.
So need need to use something like
INSERT INTO Table1 (name,address,phone,id) VALUES ('WK','Taman Pertama',NULL,4);
i.e. WK and Taman Pertama need to be enclosed in quotes the number doesn't need to be.
android.database.sqlite.SQLiteException: near "Pertama": syntax error
(code 1): , while compiling: INSERT INTOTable1
(name,address,phone,id) VALUES (WK,Taman Pertama,NULL,'4');
Is saying that you have a syntax error. Strings/Text should be enclosed in single quotes.
So need need to use something like
INSERT INTO Table1 (name,address,phone,id) VALUES ('WK','Taman Pertama',NULL,4);
i.e. WK and Taman Pertama need to be enclosed in quotes the number doesn't need to be.
answered Nov 23 '18 at 9:38
MikeTMikeT
18.4k112844
18.4k112844
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442929%2fread-files-data-android-studio%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
You need to quote string values in SQL, e.g.
'Taman Pertama'
.– Henry
Nov 23 '18 at 8:23
Sorry, What do you mean? I don't quite understand... @Henry
– Leon Zaii
Nov 23 '18 at 8:43
There are SQL syntax errors in your file
test.sql
.– Henry
Nov 23 '18 at 8:45
I changed
'Taman Pertama'
toNULL
. Also got this error @Henry– Leon Zaii
Nov 23 '18 at 8:48
your SQL query is invalid. There is no problem with reading file.
– Vladyslav Matviienko
Nov 23 '18 at 8:53