• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Exception!!

 
allen gu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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"
 
Graham Thorpe
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this way
String sql2="select * from '"+specialty3+"' where Sn='"+sn+"';";
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic