Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prepared statement error

 
mohd sherrez
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {

String tmp=(String)cb_countries.getSelectedItem();
String sql="SELECT * FROM seacountries where country=?";
try{
PreparedStatement pst=con.prepareStatement(sql);
}



catch(Exception e){

}



}
Hi guys i have an error on this part of the code PreparedStatement pst=con.prepareStatement(sql);
the con is underlined in red whats wrong?
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Have you declared con as a variable?
 
mohd sherrez
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Welcome to the Ranch!

Have you declared con as a variable?

hi how do i do that?
Connection con;
like that?
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohd sherrez wrote:
Connection con;
like that?

Ummm...yes.
Please don't take this the wrong way, but if you need to ask how to declare variables, maybe you took a few steps back and started off with basics?
Check out http://docs.oracle.com/javase/tutorial/java/javaOO/variables.html
 
mohd sherrez
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:
mohd sherrez wrote:
Connection con;
like that?

Ummm...yes.
Please don't take this the wrong way, but if you need to ask how to declare variables, maybe you took a few steps back and started off with basics?
Check out http://docs.oracle.com/javase/tutorial/java/javaOO/variables.html

the con thing dosent work even with declaration
hi i am quite advanced into java i just have trouble trying to select a combobox item from that retrieve some values from a database and display it into my jtextfields
can i ask you for some help
how do i convert the following
public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {

ResultSet rs = null;

String tmp=(String)cb_countries.getSelectedItem();
String sql="SELECT * FROM seacountries where country=?";
try{
PreparedStatement pst=con.prepareStatement(sql);
pst.setString(1, tmp);
rs=pst.executeQuery();
if(rs.next()){
String add1=rs.getString("IOC");
tb_ioc.setText(add1);


}
}



catch(Exception e){

}

//////INTO THIS FORMAT////
Step 1 -connect to database
db.getConnection();

step 2 - declare the SQL statement
String sql="SELECT * FROM seacountries where country=?";
rs = db.readRequest(dbQuery);
try{
while (rs.next())}
catch{
}
much thanks
 
Maneesh Godbole
Saloon Keeper
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohd sherrez wrote:
the con thing dosent work even with declaration

Please share your SSCCE (<-link; click to find out what it actually means) which demonstrates the problem.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic