why it error cant find symbol in
PreparedStatement ps = connection.prepareStatement(sql);
^
variable connection
but variable connection has benn declaredlike this : *i input the correct username, password and url
try {
Class.forName("org.postgresql.Driver");
}
catch (java.lang.ClassNotFoundException e) {
System.out.println(e.getMessage());
}
try {
String url = "jdbc:postgresql://stampy.db.elephantsql.com/";
String username = "";
String password = "";
Connection connection = DriverManager.getConnection(url, username, password);
List<AdvDetail> list = new ArrayList();
} catch(SQLException e) {
System.out.println(e.getMessage());
}
I have import library
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.*;
import a1.kmita.com.model.Adv;
import a1.kmita.com.model.AdvDetail;
import a1.kmita.com.listener.ExceptionListener;
import a1.kmita.com.model.Response;
and the other spring libraries
here the code
try {
String sql = "INSERT INTO advert (ad_title, ad_desc, ad_price, ad_image1,) VALUES (?, ?, ?, ?)"; /* this is the query */
PreparedStatement ps = connection.prepareStatement(sql); /* this is error */
ps.setString(1, product_name);
ps.setString(2, product_desc);
ps.setInt(3, product_price);
ps.setString(4, image1);
ps.executeUpdate();
ps.close();
} catch(SQLException e) {
System.out.println(e.getMessage());
}