Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

JMenuBar with data coming from a database source

  Asked By: Joel    Date: Oct 26    Category: Java    Views: 760
  

i am populating my JMenuBar with data coming from a database source
when i execute my prepared statement wherein a parameter does not
exist i get an error.

the code is below:

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection
("jdbc:odbc:test");
Statement state=con.createStatement();
ResultSet result1=state.executeQuery("Select * from
Project");
PreparedStatement stat1=con.prepareStatement("select
* from Well where Pid=?");


while(result1.next())
{

String s=result1.getString(2);
submenu = new JMenu(s);
menu.add(submenu);
stat1.setString(1,result1.getString(1));
ResultSet result2=stat1.executeQuery();

while(result2.next())
{
String ss=result2.getString(1);
menuitem = new JMenuItem(ss);
submenu.add(menuitem);
}
}

}
catch(Exception e)
{
System.out.println("error" + e);
}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Kristin Johnston     Answered On: Oct 26

i think that with one connection  you can not have more than one
statment, so if you already have a statement  state, and you want to
do another Statement/PreparedStatement then you have to close the
first state, but if your algorithm requires that you need more than
one query at the same time , then:
create two connection!

, but this is all assumed that you can't open more than one statement
in one connection.

 
Didn't find what you were looking for? Find more on JMenuBar with data coming from a database source Or get search suggestion and latest updates.




Tagged: