• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Prepared statement error

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Have you declared con as a variable?
 
mohd sherrez
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic