This week's book giveaway is in the Game Development forum.
We're giving away four copies of Badass: Making Users Awesome and have Kathy Sierra 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

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
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+"';";
I agree. Here's the link:
subject: SQL Exception!!