SQLite select, join and where clause problems - java
Im trying to populate a listview with data from 3 tables using join, and one table to check wether a user is part of a group. But im having trouble getting all the groups for a given user. Heres the tables
Group table
_id | group_name | group_description | group_image
User table
_id | user_name | user_image
Group participants table (this table determines which users are part of which groups)
_id | user_id_foreign | group_id_foreign
Activityobject table
_id | target_id | user_id_foreign | target_type | time | type
Here is the sql statement im trying to get to work:
Cursor c = database
.rawQuery(
"SELECT groups.*, activityobject.time, activityobject.type, user.user_name, user.user_image "
+ "FROM activityobject "
+ "JOIN user "
+ "ON user._id = activityobject.user_id "
+ "JOIN groups"
+ "ON groups._id = activityobject.target_id "
+ "WHERE groups._id IN(SELECT group_id_foreign FROM group_participants WHERE user_id_foreign = ?)"
+ "AND activityobject.target_type = 0 "
+ "GROUP BY groups._id "
+ "ORDER BY activityobject._id",
new String[] { String.valueOf(userId) });
The result i get right now are all the groups that has an activityobject, but not the ones without.
I would like to get all groups for a given user, and if a group has an activityobject i want data from that object aswell.
Thanks in advance!
EDIT:
An image of the tables im refering to
Heres my insert statements with data in the tables
//Activity object table
db.execSQL("INSERT INTO " + TABLE_ACTIVITYOBJECT + " ("
+ KEY_ACTIVITYOBJECT_ID + ", "
+ KEY_ACTIVITYOBJECT_ACTIVITY_TYPE + ", "
+ KEY_ACTIVITYOBJECT_USER_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_NAME + ", "
+ KEY_ACTIVITYOBJECT_TARGET_TYPE + ", "
+ KEY_ACTIVITYOBJECT_TIME + ", " + KEY_ACTIVITYOBJECT_OBJECT_ID
+ ") VALUES (1, 2, 1, 1, 'Alex gruppe', 0, '07-05-13', 1)");
db.execSQL("INSERT INTO " + TABLE_ACTIVITYOBJECT + " ("
+ KEY_ACTIVITYOBJECT_ID + ", "
+ KEY_ACTIVITYOBJECT_ACTIVITY_TYPE + ", "
+ KEY_ACTIVITYOBJECT_USER_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_NAME + ", "
+ KEY_ACTIVITYOBJECT_TARGET_TYPE + ", "
+ KEY_ACTIVITYOBJECT_TIME + ", " + KEY_ACTIVITYOBJECT_OBJECT_ID
+ ") VALUES (2, 2, 1, 2, 'Jeremys gruppe', 0, '08-06-13', 2)");
db.execSQL("INSERT INTO " + TABLE_ACTIVITYOBJECT + " ("
+ KEY_ACTIVITYOBJECT_ID + ", "
+ KEY_ACTIVITYOBJECT_ACTIVITY_TYPE + ", "
+ KEY_ACTIVITYOBJECT_USER_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_NAME + ", "
+ KEY_ACTIVITYOBJECT_TARGET_TYPE + ", "
+ KEY_ACTIVITYOBJECT_TIME + ", " + KEY_ACTIVITYOBJECT_OBJECT_ID
+ ") VALUES (3, 2, 1, 2, 'Jeremys gruppe', 1, '09-07-13',3)");
db.execSQL("INSERT INTO " + TABLE_ACTIVITYOBJECT + " ("
+ KEY_ACTIVITYOBJECT_ID + ", "
+ KEY_ACTIVITYOBJECT_ACTIVITY_TYPE + ", "
+ KEY_ACTIVITYOBJECT_USER_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_NAME + ", "
+ KEY_ACTIVITYOBJECT_TARGET_TYPE + ", "
+ KEY_ACTIVITYOBJECT_TIME + ", " + KEY_ACTIVITYOBJECT_OBJECT_ID
+ ") VALUES (4, 2, 1, 2, 'Jeremys gruppe', 0, '10-08-13', 4)");
db.execSQL("INSERT INTO " + TABLE_ACTIVITYOBJECT + " ("
+ KEY_ACTIVITYOBJECT_ID + ", "
+ KEY_ACTIVITYOBJECT_ACTIVITY_TYPE + ", "
+ KEY_ACTIVITYOBJECT_USER_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_NAME + ", "
+ KEY_ACTIVITYOBJECT_TARGET_TYPE + ", "
+ KEY_ACTIVITYOBJECT_TIME + ", " + KEY_ACTIVITYOBJECT_OBJECT_ID
+ ") VALUES (5, 2, 1, 1, 'Alex gruppe', 0, '11-09-13', 5)");
db.execSQL("INSERT INTO " + TABLE_ACTIVITYOBJECT + " ("
+ KEY_ACTIVITYOBJECT_ID + ", "
+ KEY_ACTIVITYOBJECT_ACTIVITY_TYPE + ", "
+ KEY_ACTIVITYOBJECT_USER_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_NAME + ", "
+ KEY_ACTIVITYOBJECT_TARGET_TYPE + ", "
+ KEY_ACTIVITYOBJECT_TIME + ", " + KEY_ACTIVITYOBJECT_OBJECT_ID
+ ") VALUES (6, 2, 1, 1, 'Alex gruppe', 0, '12-10-13', 6)");
db.execSQL("INSERT INTO " + TABLE_ACTIVITYOBJECT + " ("
+ KEY_ACTIVITYOBJECT_ID + ", "
+ KEY_ACTIVITYOBJECT_ACTIVITY_TYPE + ", "
+ KEY_ACTIVITYOBJECT_USER_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_NAME + ", "
+ KEY_ACTIVITYOBJECT_TARGET_TYPE + ", "
+ KEY_ACTIVITYOBJECT_TIME + ", " + KEY_ACTIVITYOBJECT_OBJECT_ID
+ ") VALUES (7, 2, 1, 1, 'Alex gruppe', 1, '13-11-13', 7)");
db.execSQL("INSERT INTO " + TABLE_ACTIVITYOBJECT + " ("
+ KEY_ACTIVITYOBJECT_ID + ", "
+ KEY_ACTIVITYOBJECT_ACTIVITY_TYPE + ", "
+ KEY_ACTIVITYOBJECT_USER_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_ID + ", "
+ KEY_ACTIVITYOBJECT_TARGET_NAME + ", "
+ KEY_ACTIVITYOBJECT_TARGET_TYPE + ", "
+ KEY_ACTIVITYOBJECT_TIME + ", " + KEY_ACTIVITYOBJECT_OBJECT_ID
+ ") VALUES (8, 2, 1, 1, 'Alex gruppe', 0, '14-12-13', 8)");
// Group table
db.execSQL("INSERT INTO " + TABLE_GROUP + " ( " + KEY_GROUP_ID + ", "
+ KEY_GROUP_NAME + ", " + KEY_GROUP_INFO + ", "
+ KEY_GROUP_IMAGE
+ ") VALUES (1,'alex gruppe', 'mega awesome gruppe', null);");
db.execSQL("INSERT INTO " + TABLE_GROUP + " ( " + KEY_GROUP_ID + ", "
+ KEY_GROUP_NAME + ", " + KEY_GROUP_INFO + ", "
+ KEY_GROUP_IMAGE
+ ") VALUES (2,'jeremy gruppe', 'mega awesome gruppe', null);");
db.execSQL("INSERT INTO " + TABLE_GROUP + " ( " + KEY_GROUP_ID + ", "
+ KEY_GROUP_NAME + ", " + KEY_GROUP_INFO + ", "
+ KEY_GROUP_IMAGE
+ ") VALUES (3,'ole gruppe', 'mega awesome gruppe', null);");
db.execSQL("INSERT INTO " + TABLE_GROUP + " ( " + KEY_GROUP_ID + ", "
+ KEY_GROUP_NAME + ", " + KEY_GROUP_INFO + ", "
+ KEY_GROUP_IMAGE
+ ") VALUES (4,'egon gruppe', 'mega awesome gruppe', null);");
// User table
db.execSQL("INSERT INTO " + TABLE_USER + " (" + KEY_USER_ID + ", "
+ KEY_USER_NAME + ", " + KEY_USER_IMAGE + ", "
+ KEY_USER_STATUS + ") VALUES (1, 'Alex', null, 0)");
db.execSQL("INSERT INTO " + TABLE_USER + " (" + KEY_USER_ID + ", "
+ KEY_USER_NAME + ", " + KEY_USER_IMAGE + ", "
+ KEY_USER_STATUS + ") VALUES (2, 'Peter', null, 0)");
db.execSQL("INSERT INTO " + TABLE_USER + " (" + KEY_USER_ID + ", "
+ KEY_USER_NAME + ", " + KEY_USER_IMAGE + ", "
+ KEY_USER_STATUS + ") VALUES (3, 'Jeremy', null, 0)");
db.execSQL("INSERT INTO " + TABLE_USER + " (" + KEY_USER_ID + ", "
+ KEY_USER_NAME + ", " + KEY_USER_IMAGE + ", "
+ KEY_USER_STATUS + ") VALUES (4, 'Søren', null, 0)");
db.execSQL("INSERT INTO " + TABLE_USER + " (" + KEY_USER_ID + ", "
+ KEY_USER_NAME + ", " + KEY_USER_IMAGE + ", "
+ KEY_USER_STATUS + ") VALUES (5, 'Ole', null, 0)");
// Group participants table
db.execSQL("INSERT INTO " + TABLE_GROUP_PARTICIPANTS + " ( "
+ KEY_GROUP_PARTICIPANTS_ID + ", "
+ KEY_GROUP_PARTICIPANTS_USER_ID_FOREIGN + ", "
+ KEY_GROUP_PARTICIPANTS_GROUP_ID_FOREIGN + ") VALUES(1, 1, 1)");
db.execSQL("INSERT INTO " + TABLE_GROUP_PARTICIPANTS + " ( "
+ KEY_GROUP_PARTICIPANTS_ID + ", "
+ KEY_GROUP_PARTICIPANTS_USER_ID_FOREIGN + ", "
+ KEY_GROUP_PARTICIPANTS_GROUP_ID_FOREIGN + ") VALUES(2, 1, 4)");
db.execSQL("INSERT INTO " + TABLE_GROUP_PARTICIPANTS + " ( "
+ KEY_GROUP_PARTICIPANTS_ID + ", "
+ KEY_GROUP_PARTICIPANTS_USER_ID_FOREIGN + ", "
+ KEY_GROUP_PARTICIPANTS_GROUP_ID_FOREIGN + ") VALUES(3, 2, 2)");
"I would like to get all groups for a given user, and if a group has an activityobject i want data from that object aswell."
You have to use a LEFT JOIN then.
select g.*, a.time, a.type, u.user_name, u.user_image
from groups g
join group_participants gp on gp.group_id_foreign = g._id
left join activityobject a on g._id = a.target_id and a.target_type = 0
left join user u on a.user_id_foreign = u.id
where gp.user_id_foreign = ?
order by a._id;
If you just want to select the last activity object per group (if any), you can add that to the join condition, too:
select g.*, a.*
from groups g
join group_participants gp on gp.group_id_foreign = g._id
left join activityobject a
on g._id = a.target_id and
a.target_type = 0 and
a._id in (select max(_id) from activityobject group by target_id)
left join users u on a.user_id_foreign = u.id
where gp.user_id_foreign = ?
order by a._id;
Just keep in mind that you have to add all filtering criteria for activityobjects to the join condition of the left join, not to the where clause of your main query. Otherwise, you will surpress rows from the result where no matching activityobject can be found, instead of filling up the columns with nulls.
Related
sqlite JOIN query for multiple entries
My database has "diary" table and "food" table. In diary table I have following columns: date, food1,food2, ...food10. In food table I have: id, name, allergen1, allergen2, allergen3. So basically you log up to 10 foods a day to diary. Now I'm trying to build a query which would let me find last date that I've eaten food with allergen3. So that's the query I came up with, which you probably know is not working ;-) Cursor findDateRes = db.rawQuery("SELECT date(" + DIARY_COL_DATE + ") FROM " + DIARY_TABLE + " INNER JOIN " + FOOD_TABLE + " food1 ON (food1." + FOOD_COL_1 + " = " + DIARY_TABLE + "." + DIARY_COL_F1 + ")" + " INNER JOIN " + FOOD_TABLE + " food2 ON (food2." + FOOD_COL_1 + " = " + DIARY_TABLE + "." + DIARY_COL_F2 + ")" + " INNER JOIN " + FOOD_TABLE + " food3 ON (food3." + FOOD_COL_1 + " = " + DIARY_TABLE + "." + DIARY_COL_F3 + ")" + " INNER JOIN " + FOOD_TABLE + " food4 ON (food4." + FOOD_COL_1 + " = " + DIARY_TABLE + "." + DIARY_COL_F4 + ")" + " INNER JOIN " + FOOD_TABLE + " food5 ON (food5." + FOOD_COL_1 + " = " + DIARY_TABLE + "." + DIARY_COL_F5 + ")" + " INNER JOIN " + FOOD_TABLE + " food6 ON (food6." + FOOD_COL_1 + " = " + DIARY_TABLE + "." + DIARY_COL_F6 + ")" + " INNER JOIN " + FOOD_TABLE + " food7 ON (food7." + FOOD_COL_1 + " = " + DIARY_TABLE + "." + DIARY_COL_F7 + ")" + " INNER JOIN " + FOOD_TABLE + " food8 ON (food8." + FOOD_COL_1 + " = " + DIARY_TABLE + "." + DIARY_COL_F8 + ")" + " INNER JOIN " + FOOD_TABLE + " food9 ON (food9." + FOOD_COL_1 + " = " + DIARY_TABLE + "." + DIARY_COL_F9 + ")" + " INNER JOIN " + FOOD_TABLE + " food10 ON (food10." + FOOD_COL_1 + " = " + DIARY_TABLE + "." + DIARY_COL_F10 + ") WHERE 1 NOT IN (food1." + FOOD_COL_5 + ",food2." + FOOD_COL_5 + ",food3." + FOOD_COL_5 + ",food4." + FOOD_COL_5 + ",food5." + FOOD_COL_5 + ",food6." + FOOD_COL_5 + ",food7." + FOOD_COL_5 + ",food8." + FOOD_COL_5 + ",food9." + FOOD_COL_5 + ",food10." + FOOD_COL_5 + ") ORDER BY date(" + DIARY_COL_DATE + ") ASC LIMIT 1", null); "FOOD_COL_1" stands for id and "FOOD_COL_5" stands fro allergen3. Thank you for looking. Any input will be appreciated.
java.lang.IllegalArgumentException: column 'foo' does not exist android
Numerous StackOverflow problems are similar, but it is not an issue of incorrect spacing in the query string. I have two tables, one for peers and one for messages, which has foreign keys associated with ids in the peer table. Here are my creation strings: private static final String DATABASE_CREATE = "CREATE TABLE " + PEER_TABLE + " (" + PeerContract._ID + " INTEGER PRIMARY KEY, " + PeerContract.NAME + " TEXT NOT NULL, " + PeerContract.ADDRESS + " TEXT NOT NULL, " + PeerContract.PORT + " TEXT NOT NULL);"; private static final String MESSAGE_TABLE_CREATE = "CREATE TABLE " + MESSAGE_TABLE + " (" + MessageContract._ID + " INTEGER PRIMARY KEY, " + MessageContract.MESSAGE_TEXT + " TEXT NOT NULL, " + MessageContract.SENDER + " TEXT NOT NULL, " + MessageContract.PEER_FOREIGN_KEY + " INTEGER NOT NULL, " + "FOREIGN KEY ("+ MessageContract.PEER_FOREIGN_KEY+") " + "REFERENCES "+PEER_TABLE+"("+PeerContract._ID+") ON DELETE CASCADE);"; private static final String CREATE_INDEX = "CREATE INDEX " + INDEX + " ON " + MESSAGE_TABLE + "(" + MessageContract.PEER_FOREIGN_KEY + ");"; I want to query a list of all received messages so I did this: public Cursor fetchAllMessages(){ String query = "SELECT " + MESSAGE_TABLE + "." + MessageContract._ID + ", " + MessageContract.MESSAGE_TEXT + ", " + MessageContract.SENDER + " FROM " + MESSAGE_TABLE + " JOIN " + PEER_TABLE + " ON " + MESSAGE_TABLE + "." + MessageContract.PEER_FOREIGN_KEY + "=" + PEER_TABLE + "." + PeerContract._ID; return db.rawQuery(query, null); } Which makes sense to me. And the spacing so far is alright there is no errors. In my main activity I have a SimpleCursorAdapter: listView = (ListView) findViewById(R.id.msgList); dbAdapter = new ServerDbAdapter(this); dbAdapter.open(); String[] from = new String[] {PeerContract.NAME, MessageContract.MESSAGE_TEXT}; int[] to = new int[] {android.R.id.text1, android.R.id.text2}; cursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor, from, to); listView.setAdapter(cursorAdapter); cursor = dbAdapter.fetchAllMessages(); cursorAdapter.swapCursor(cursor); I get "column 'name' does not exist" and it is driving me crazy! I properly defined it in DATABASE_CREATE as PeerContract.NAME. I'm guessing its happening because of fetchAllMessages but I am not sure how to fix it.
You are not selecting the PeerContract.NAME, MessageContract.MESSAGE_TEXT in your fetchAllMessages() method. Change it to this: public Cursor fetchAllMessages(){ String query = "SELECT " + MESSAGE_TABLE + "." + MessageContract._ID + ", " + MessageContract.MESSAGE_TEXT + ", " + PeerContract.NAME + ", " + PeerContract.MESSAGE_TEXT + ", " + MessageContract.SENDER + " FROM " + MESSAGE_TABLE + " JOIN " + PEER_TABLE + " ON " + MESSAGE_TABLE + "." + MessageContract.PEER_FOREIGN_KEY + "=" + PEER_TABLE + "." + PeerContract._ID; return db.rawQuery(query, null); }
Hql Query.nor working
I need to write the query according to this logic LeadRepository.getQualifiedLeadsWithoutClosedWonOrLost to the following query: select l.id from prospectr360.lead l, prospectr360.lead_action la where l.id = la.lead_id and la.action_id = 6 and l.id not in (select l.id from prospectr360.lead_action la, prospectr360.action a, prospectr360.lead l where la.action_id = a.id and la.lead_id = l.id and reason_id in (61,65)) and I have written #Query("SELECT lead.id " + " FROM Lead lead, " + " LeadAction la, " + " WHERE lead.id = leadAction.lead.id"+ " AND leadAction.action.id = 6" + " WHERE NOT EXISTS (SELECT 1 " + " FROM Lead lead, " + " Action action, " + " WHERE action.id = la.action.id" + " AND la.lead.id = lead.id" + " AND la.reason.id in (61,65)" + ")") List<Lead> getQualifiedLeadsWithoutClosedWonOrLost(); }
I resolved it #Query("SELECT lead " + " FROM Lead lead, " + " LeadAction leadAction " + " WHERE lead.id = leadAction.lead.id"+ " AND leadAction.action.id = 6" + " AND lead.id NOT IN (SELECT lead1.id " + " FROM Lead lead1, " + " LeadAction la ," + " Action action " + " WHERE la.action.id = action.id" + " AND la.lead.id = lead1.id" + " AND la.reason.id in (61,65)" + ")") List<Lead> getQualifiedLeadsWithoutClosedWonOrLost();
"No such column" when running update on SQLite
I'm trying to update a row in my database. Here is the code I am trying to use to update: public void addFBComments(int id){ SQLiteDatabase db = this.getWritableDatabase(); String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS+"="+"HELLO" + " WHERE " + COL_FB_ID+"="+id; db.execSQL(query); } When I run the command, it throws this error: 08-18 15:42:10.145: E/AndroidRuntime(10493): FATAL EXCEPTION: Thread-922 08-18 15:42:10.145: E/AndroidRuntime(10493): android.database.sqlite.SQLiteException: no such column: HELLO (code 1): , while compiling: UPDATE fb_feed SET fb_comments= HELLO WHERE _id=3 Here is the TABLE_FB_FEED: private static final String TABLE_FB_FEED_CREATE = "create table " + TABLE_FB_FEED + " (" + COL_FB_ID + " integer primary key autoincrement not null," + COL_FB_MESSAGE + " text," + COL_FB_CAPTION + " text," + COL_FB_POSTER_ID + " text," + COL_FB_POST_ID + " text," + COL_FB_LIKES + " text," + COL_FB_POSTER_NAME + " text," + COL_FB_COMMENTS + " text," // this is the column i want to update + COL_FB_LIKES_NUM + " text," + COL_FB_TIMESTAMP + " text," + COL_FB_PROFILE_PICTURE_URI + " text," + COL_FB_PICTURE_URI + " text," + COL_FB_NAME + " text," + COL_FB_PREVIOUS_PAGE_URI + " text," + COL_FB_NEXT_PAGE_URI + " text," + COL_FB_POST_TYPE + " text," + COL_FB_LINK_NAME + " text," + COL_FB_COMMENTS_NUM + " text," + COL_FB_STORY + " text," + COL_FB_DESCRIPTION + " text," + COL_FB_COMMENTS_BEFORE + " text," + COL_FB_COMMENTS_AFTER + " text," + COL_FB_LIKES_PROFILE_PIC + " text," + COL_FB_COMMENTS_PROFILE_PIC + " text);"; Why is it throwing the query? I thought I was doing everything correctly.
in your code you need to add single quotes: String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS +"="+"'HELLO'" + " WHERE " + COL_FB_ID+"="+id or String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS +"='HELLO' WHERE " + COL_FB_ID+"="+id this is another example "UPDATE DB_TABLE SET YOUR_COLUMN='newValue' WHERE id=myidValue");
In SQL, string values must be quoted: String query = "..." + COL_FB_COMMENTS+"= 'HELLO' WHERE ..."; Anyway, formatting problems such as this (which get worse when the string itself contains quotes) can be avoided by using parameters: String query = "... SET " + COL_FB_COMMENTS+"= ? WHERE " + COL_FB_ID+"="+id; db.execSQL(query, new Object[] { "HELLO" });
You need to escape your String literal, String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS +"="+"HELLO" + " WHERE " + COL_FB_ID+"="+id Could be String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS +"="+"'HELLO'" + " WHERE " + COL_FB_ID+"="+id Or, you could use a bind parameter.
something like String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS+"="+"'HELLO'" + " WHERE " + COL_FB_ID+"="+id; would work
Cannot insert data into Database( Syntax error into INSERT INTO Statement)
private void addCustomerActionPerformed( ActionEvent e ) { String Query; Query = "INSERT INTO Membership VALUES"+ "(' " +memberID_a.getText() + " ' , ' " +memberName_a.getText() + " ' , ' " + icNo_a.getText() + " ', ' " + gender_a.getText() +" ' , '" + birthday_a.getText() +" ' , ' " + telephoneNo_a.getText() + " ',' " + mobileNo_a.getText() + " ' , ' " + email_a.getText() + " ' , ' " + address_a.getText() + " ' , " + postalCode_a.getText() + " ,' " + state_a.getText() + " ' , '" + country_a.getText() + " ' , " + memberPoint_a.getText() + ");"; try { stmtInsert = conn.createStatement(); stmtInsert.executeUpdate(Query); } catch(Exception ex){ JOptionPane.showMessageDialog(null,"ERROR"+ex.toString(),"ERROR",JOptionPane.ERROR_MESSAGE); } } I am getting the error of java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement. Anyone help me with this problem ? thanks
This will work Query ="INSERT INTO Membership VALUES ( " +memberID_a.getText() + " , " +memberName_a.getText() + " , " + icNo_a.getText() + " , " + gender_a.getText() +" ," + birthday_a.getText() +"," + telephoneNo_a.getText() + " , " + mobileNo_a.getText() + " , " + email_a.getText() + " , " + address_a.getText() + " , " + postalCode_a.getText() + ", " + state_a.getText() + " ," + country_a.getText() + "," + memberPoint_a.getText() + ")";