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))
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 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;
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
I'm getting this error when I'm trying to connect my Java Plugin to the local MySQL database:
[01:15:44 INFO]: [BetterStaff] Could not connect to database: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 ''Reportslog' ('SenderName' varchar(32), 'Message' string)' at line 1
The code from my plugin is:
this.db.openConnection();
Statement statement = this.db.getConnection().createStatement();
statement.executeUpdate("CREATE TABLE IF NOT EXISTS 'Reportslog' ('SenderName' varchar(32), 'Message' string)");
Can you help me or correct my SQL syntax please?
Quotes are not allowed in the table name or fields:
String sql =
"CREATE TABLE IF NOT EXISTS Reportslog (SenderName varchar(32), Message varchar(32))";
PreparedStatement preparedStatement = conn.prepareStatement(sql);
preparedStatement.executeUpdate();
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";