swing apps with jdbc connectivity and mysql [closed] - java

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)

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();

Column not found in Left Join [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 5 years ago.
Improve this question
"SELECT `articles`.`name`, `articles`.`description`,`articles`.`startPrice`,`articles`.`creationDate`,"
+ "`bids`.`date`, `bids`.`price`,`bids`.`userId`"
+ " FROM `articles` LEFT JOIN `bids` ON `articles`.`id` = `bids`.`articleId`"
+ " WHERE 1"
java.sql.SQLException: Column '`articles`.`id`' not found.
bids table has not records, but just wanted to try that, since I understand that the Left Join shows all the records in the table on the left although the right table has no records.
I have changed Left Join by Inner Join and the query runs without errors
with result of zero records (as expected).
MySql version is 5.7.18
articles table:
Some Test:
Example of a query that work Ok without errors:
"select `articles`.`id`, `articles`.`name`, `articles`.`description`,`articles`.`startPrice`,`articles`.`creationDate`," +
"`bids`.`date`, `bids`.`price`,`bids`.`userId`"
+ " FROM `articles` INNER JOIN `bids` ON `articles`.`id` = `bids`.`articleId` "
+ " WHERE 1"
I also try to restart my MySql server and the same thing happens
I am using java and JDBC with
statement.executeQuery()
I do not know why but it was fixed using the Java Statement class instead of PreparedStatement to execute query.
Try this:
"SELECT `articles`.`name`, `articles`.`description`,`articles`.`startPrice`,`articles`.`creationDate`,"
+ "`bids`.`date`, `bids`.`price`,`bids`.`userId`"
+ " FROM `articles` LEFT JOIN `bids` ON `bids`.`articleId` = `articles`.`id`"
+ " WHERE 1"

Sql to java JDBC database [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 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
}

javafx loading detail for sql query execute [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 8 years ago.
Improve this question
i am working on javafx project and i want to create a loading sign on execution of my sql query but how could i know every part of execution of my query .
My code:
Thread df1=new Thread(){
public void run(){
for(int i=1;i<=1;i++){
try{
System.out.print("1%");
Class.forName("com.mysql.jdbc.Driver");
Connection con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/sql541774","sql541774","password");
String sql="Select * from messanger";
Statement stm=(Statement) con.createStatement();
ResultSet rs=stm.executeQuery(sql);
textmess.setText("");
while(rs.next()){
String sc=rs.getString(2);
String sc1=rs.getString(3);
String sc2=rs.getString(4);
}
rs.close();
stm.close();
con.close();
System.out.print("100%");
} catch(Exception e){
}
}
}
};
df1.start();
it shows me output
1% 100%
how i will able to get true output like:
1% 2% 3% .........98% 99% 100%
Please help me. Thank you.
First: remove the for loop, its useless.
Second: You cannot do that. There is no way to know in advance how long your statement will take. This depends on things like how many data you request, the network speed, other statements executed in the same moment or how much other load is on the machine.
What you could to is the following (in pseudo code): Request how many rows are there in total and get row by row. On each row, you can increase the loading bar. You can split the loading bar by the number of rows or you can calculate how many rows would be 1%.
int numberOfRows = SELECT COUNT(*) FROM MESSANGER;
for(i in numberOfRows)
row = SELECT * FROM MESSANGER WHERE ID = i
print i + " rows from " + numberOfRows + " rows loaded"

Categories