简体   繁体   中英

How to fix Error: Unresolved compilation problems: Syntax error on token “rs”

Can someone please tell me what is the compilation error

"Exception in thread "main" java.lang.Error: Unresolved compilation problems: Syntax error on token "rs", delete this token The method getString(int) is undefined for the type String at SelectTest.main"

in the below java code

//SelectTest.java
import java.sql.*;
public class SelectTest1
{
    public static void main(String args[])throws Exception
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:oradsn","System","123");
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("select*from student");
        {
            while(rs.next())
            {
                System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "rs.getString(3));
            }
            rs.close();
            st.close();
            con.close();
        }
    }
}

最后一个rs.getString(3)您忘记了“ +”

System.out.println(rs.getInt(1)+" "+rs.getString(2)+" " +rs.getString(3));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM