aspose file tools*
The moose likes JDBC and the fly likes SQL Exception!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Exception!!" Watch "SQL Exception!!" New topic
Author

SQL Exception!!

allen gu
Greenhorn

Joined: Jan 13, 2003
Posts: 6
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

Joined: Mar 25, 2002
Posts: 265
try this way
String sql2="select * from '"+specialty3+"' where Sn='"+sn+"';";
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SQL Exception!!