• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

SQL Exception!!

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String sn=edit1.getText();
try {
Connection con=null;
ResultSet rs;
ResultSetMetaData md;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
String url="jdbc dbc:test1";
con=DriverManager.getConnection(url,"","");
Statement s=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String sql1="select Specialty from student where Sn='"+sn+"';" ;
rs=s.executeQuery(sql1);//sql1 is ok!
if(!rs.next())
{
labeld.setText("Can not find!");
}
else
{
String specialty3=rs.getString("Specialty");
System.out.println(specialty3);
String sql2="select * from "+specialty3+" where Sn='"+sn+"';";
System.out.println(sql2);
rs=s.executeQuery(sql2);// sql2 throw a sql Exception! "Illegal description index"
 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this way
String sql2="select * from '"+specialty3+"' where Sn='"+sn+"';";
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic