Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
This is my database table call "BREAKFAST_TABLE" I want to keep date that not duplicate to list
This is my code
public List<String> get_notSameDate(String status)
{
List<String> return_Food=new ArrayList<>();
//COLUMN_DATE is "DATE"
//status is "BREAKFAST_TABLE"
String queryString="SELECT DISTINCT"+COLUMN_DATE+" FROM "+status;
SQLiteDatabase db=this.getReadableDatabase();
Cursor cursor = db.rawQuery(queryString,null);
if(cursor.moveToFirst())
{
do {
String date=cursor.getString(0);
return_Food.add(date);
}while (cursor.moveToNext());
}
cursor.close();
db.close();
return return_Food;
}
I using this code it always crashes.
Though we don't know what error it crashes with, I believe it fails because of missing space symbol between "DISTINCT" and the column name:
"SELECT DISTINCT"+COLUMN_DATE+" FROM "+status;
fixed:
"SELECT DISTINCT "+COLUMN_DATE+" FROM "+status;
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I use following code to run mongodb dbStats command to get more details of databases:
public static void main(String[] args) {
MongoClient mongoClient = new MongoClient("127.0.0.1", 27017);
MongoIterable<String> databases = mongoClient.listDatabaseNames();
for (String dbName : databases) {
System.out.println("- Database: " + dbName);
MongoDatabase db = mongoClient.getDatabase(dbName);
Document result = db.runCommand(new Document("dbStats", "1"));
// read required database details
}
mongoClient.close();
}
That's based on MogoDB documentation (https://docs.mongodb.com/manual/reference/command/dbStats/), it should work correctly, but it throws exception:
Command failed with error 73 (InvalidNamespace): 'Invalid db name: dbname.1' on server 127.0.0.1:27017. The full response is {....}
Thanks ernest_k, it was careless,So this works:
db.runCommand(new Document("dbStats", 1))
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
PreparedStatement amovie = con.prepareStatement("INSERT INTO actor_movie(actor_ID, movie_ID)"+ "select actor_ID from actor" + "where actor.surname = 'Depp', select movie_ID from movie where movie.title LIKE 'Caribbean%'");
Can someone tell me what is wrong with this query ? I digged the internet, but can't find a solution.
Error Message :
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', select movie_ID from movie where title LIKE 'Caribbean%'' at line 1
You have syntax error because you forgot VALUES and to enclose in parentheses the SELECT statements.
Change to this:
PreparedStatement amovie = con.prepareStatement(
"INSERT INTO actor_movie(actor_ID, movie_ID) VALUES ((select actor_ID from actor where actor.surname = 'Depp'), (select movie_ID from movie where movie.title LIKE 'Caribbean%'))");
Careful with the spaces needed between the strings concatenate
...movie_ID)"+ "select ...
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
My columns at customer table
cusid cusname cusadress paidamount email
cus123 damidu kegalle 45 adfff
This is my Java query
String query = "UPDATE `customer` SET `cusname`='"+jTextField_name.getText()+"',`cusadress`='"+jTextField_adress.getText()+"',`paidamount`='"+jTextField_amount.getText()+"',`email`="+jTextField_emailuser.getText()+" WHERE `cusid` = "+jTextField_id.getText();
executeSQlQuery(query, "Updated");
Error
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'cus123' in 'where clause'
What is the reason for this update is not working , but insert and delete statement works?
Use PreparedStatement like this below :
String updateQuery = "UPDATE customer SET cusname=?,cusadress=?,paidamount=?,email=? WHERE cusid=?";
PreparedStatement stmt=con.prepareStatement(updateQuery); // con is reference variable of Connection class
stmt.setString(1, jTextField_name.getText());
stmt.setString(2, jTextField_adress.getText());
stmt.setInt(3, jTextField_amount.getText());
stmt.setString(4, jTextField_emailuser.getText());
stmt.setString(5, jTextField_id.getText());
Hope this helps.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a problem with searching a particular contact using part of a name. I know how it would look like in SQL but I cant implement it using Java.
if (rs.getString(nameTable LIKE '%name1%';)
Consider adding the LIKE clause to your SQL query instead of handling it in java code:
try(PreparedStatment ps = con.prepareStatement("SELECT * " +
" FROM Contact WHERE contactName like ?")) {
ps.setString(1, "%name1%");
try(ResultSet rs = ps.executeQuery()) {
while(rs.next()) {
//process your data
}
}
} catch(Exception e) {
//deal with it
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Below code gives
ORA-00933: SQL command not properly ended
on
private final String DUPLICATE_SQL_1="select abc, count(abc)"
+"from table_1"
+"where type= 'NEW'"
+"and trunc(update_date) = trunc(sysdate)"
+"group by abc having count(abc)>1";
ResultSet rs = stmt.executeQuery(DUPLICATE_SQL_1);
Same query worked fine on Oracle SQL Developer.
You are missing spaces (you must have a space at the end of each line except the last or at the start of each line except the first):
private final String DUPLICATE_SQL_1="select abc, count(abc) "
+"from table_1 "
+"where type= 'NEW' "
+"and trunc(update_date) = trunc(sysdate) "
+"group by abc having count(abc)>1";