select * in java error

时间:2015-03-15 17:04:15

标签: java jdbc

package connectdatabase;
import java.sql.* ; 
public class ConnectDatabase {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver") ;
            String url = "jdbc:mysql://localhost/student" ;
            Connection db = DriverManager.getConnection(url , "root" , "") ;
            Statement sqlc = db.createStatement() ; 
            ResultSet re = sqlc.executeQuery("SELECT * FORM studentdetail ") ;
            while(re.next()) {
                System.out.println("product is = "+ re.getString("Stu_name")) ; 
            }
        }
        catch(Exception e){
            System.out.println(e);
        }
    } 
}

错误代码:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:SQL语法中有错误;检查与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在“学生”附近使用'在第1行

1 个答案:

答案 0 :(得分:1)

你有一个错字:

SELECT * FROM studentdetail 

而不是

SELECT * FORM studentdetail