aspose file tools*
The moose likes Java in General and the fly likes Prepared statement error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Prepared statement error" Watch "Prepared statement error" New topic
Author

Prepared statement error

mohd sherrez
Greenhorn

Joined: Aug 03, 2014
Posts: 10
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

Joined: Jul 26, 2007
Posts: 10535
    
    9

Welcome to the Ranch!

Have you declared con as a variable?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
mohd sherrez
Greenhorn

Joined: Aug 03, 2014
Posts: 10
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

Joined: Jul 26, 2007
Posts: 10535
    
    9

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

Joined: Aug 03, 2014
Posts: 10
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

Joined: Jul 26, 2007
Posts: 10535
    
    9

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
 
subject: Prepared statement error