Searching MongoDB using NetBeans [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 days ago.
Improve this question
I have a project that's due in 3 days and this is the last step and I can't make it work. I connected MongoDB to NetBeans by downloading mongo-java-driver-2.13.3.
I have a homepage from which user will enter information in any of the fields (street, borough, cuisine, grade, name) and you must display the result back to user. If no restaurant matches the entered information, display a message to the user that no result. My code prints all info. I want it to be in text area and only print selected info.
Here is what I wrote:
private void btnfindActionPerformed(java.awt.event.ActionEvent evt) {// TODO add your handling code here:
DBCursor cursor =table.find();
while (cursor.hasNext())
{
//jTextArea1.setText(jTextArea1.getText()+"\n"+cursor.next());
System.out.println(cursor.next());
}
}

Maybe you need to do something like that...
while (cursor.hasNext()){
BasicDBObject object = (BasicDBObject) cursor.next();
String name = object.getString("name_of_column");
jTextArea1.setText(name);
https://www.baeldung.com/java-mongodb
mongodb - java get field value

Related

jdbc template getString on UUID not working [closed]

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 1 year ago.
Improve this question
I have this method.
I am using jdbcTemplate query and then I am trying to return the list, however I am getting this error:
Required type UUID provided String
public List<Person> getPeople() {
String sql = "SELECT * from people";
List<Person> people = jdbcTemplate.query(sql, (rs, idx) -> {
return new Person(
result.getString("id"); <-------------- says can't fetch string because it's uuid type in db
)
})
}
What do I need to use instead of getString in order for this to work?
Try using getObject and casting it to UUID: result.getObject("id", java.util.UUID.class)

JDBC delete method seems to not be working in my Spring Boot service [closed]

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 1 year ago.
Improve this question
I'm trying to create a simple JDBC method to delete from my DB, and I'm not sure if I'm going about this the correct way. This is inside one of my services.
Method:
public void deleteLocation(Integer id) {
String DELETE = "DELETE FROM locale WHERE id=?";
namedParameterJdbcTemplate.update(DELETE, new BeanPropertySqlParameterSource(id));
}
I would try changing your update line to
namedParameterJdbcTemplate.update(DELETE, id);.
If you are using spring-boot. Then you should be using spring-data-jpa to manage your database. Jdbc is Hard way of doing this.
If you are using jdbc delete to a specific row use prepared statement. You can refer this:
preparedStatement = connection.prepareStatement("DELETE * from table_name WHERE id= ?");
preparedStatement.setInt(1, id);
return !preparedStatement.execute();

How to fetch users data in firebase specifically [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm developing an app in which each user must log-in first then they are able to add some objects . every objects they create will be save on firebase . but i want to separate user's obeject ! for example if user A save X and user B save Y , they must only access to their objects(user A must only have access to X) , but i don't know why anybody adds anything others have access to it ! got any idea?
in order to achieve your criteria , add an child attribute to your object node called user (the user who added that object) and then you could do a filter while requesting the data this way :
DatabaseReference mDatabaseReference = FirebaseDatabase.getInstance().getReference("Object");
Query query = mDatabaseReference.orderByChild("user").equalTo("the_user_name").addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot datas: dataSnapshot.getChildren()){
//here you get your object data
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
If you're trying to ensure that users can only access their own data, have a look at Firebase's server side security for Firestore, or for Realtime Database. These allow you to determine what data each user can access by specifying rules that are enforced on the server, so that they can't bypassed by any malicious client.

swing apps with jdbc connectivity and mysql [closed]

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 5 years ago.
Improve this question
stmt.executeUpdate("update fees set term_1 = "+hm.get("term_1").toString()+" term_2 ="+hm.get("term_1").toString()+"total = "+hm.get("total").toString()+"id = "+std_id);
Why it is not working when it is connected to JDBC?
Your update statement is invalid, you are missing comma(,)
Correct SQL Update statement should be
update fees set term_1 = 'something', term_2='something', total='something' where id = something;
So your final Java statement will be like:
stmt.executeUpdate( " Update fees set term_1 = '"+hm.get("term_1").toString()+"',"
+ " term_2 ='"+hm.get("term_1").toString()+"',"
+ " total = "+hm.get("total").toString()+"'"
+ " where id ="+std_id);
Note : Assuming all columns apart from id are of String type (i.e. term_1,term_2,total)

Hibernate: HQL is not working [closed]

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 wrote a SQL query in my hibernate application using where clause and and .
Here is method ,
public List<Comobility> getComobilityByIdComobilityItemsAndIdPatient(int idComobilityItems, int idPatient, Session session) {
Query query = session.createQuery("from Comobility where comobility_items_idcomobility_items= :idComobilityItems and patient_idpatient= :idpatinet");
query.setParameter("idComobilityItems", idComobilityItems);
query.setParameter("idpatinet", idPatient);
List<Comobility> list = query.list();
return list;
}
But this is not working . There is no any exception or error . Actually, there is no any result.
Have any ideas ?
You should try like that
Wrap your method with try catch block. I believe the query has an error then it will enter to catch block
public List<Comobility>getComobilityByIdComobilityItemsAndIdPatient(int idComobilityItems, int idPatient, Session session) {
try {
logger.debug("xxxx")
//do comething
} catch (Exception e) {
e.printStackTrace();
}
}
Make sure your method parameters are not null
Check your list is empty or not.
For checking you can use IDE debugger or put some logs in your method.
You need to check the generated SQL in the log and execute it against database. If query is compiled and no records are returned, means there are no records for the particular criteria.
To generate the SQL by Hibernate, please set property show_sql to true in hibernate configuration.

Categories