This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "SQL Exception!!" Watch "SQL Exception!!" New topic

SQL Exception!!

allen gu

Joined: Jan 13, 2003
Posts: 6
String sn=edit1.getText();
try {
Connection con=null;
ResultSet rs;
ResultSetMetaData md;
String url="jdbc dbc:test1";
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!
labeld.setText("Can not find!");
String specialty3=rs.getString("Specialty");
String sql2="select * from "+specialty3+" where Sn='"+sn+"';";
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+"';";
Have you checked out Aspose?
subject: SQL Exception!!
jQuery in Action, 3rd edition