0

I'm try to execute a SQL query using java PreparedStatement in JAVA 8 and code blow

        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        con = DriverManager.getConnection(URl,user,"");
        String sql = "Select Grade from XS_KC where Snum=? and Cnum=?";
        PreparedStatement pst = con.prepareStatement(sql);
        pst.setString(1, "020101");
        pst.setString(2, "102");
        rs = pst.executeQuery();
        while(rs.next())
        {
            System.out.print(rs.getString(1));
        }

I get the fllowing error:com.microsoft.sqlserver.jdbc.SQLServerException:parameter index out of range But if i use

stat = con.createStatement();
rs = stat.executeQuery("Select Grade from XS_KC where Snum='020101' and Cnum='101'");

I can get the result What's wrong??

2
  • You have different column names, different values (101 vs 102)... makes me wonder what the actual code and SQL statements are Commented Nov 11, 2017 at 17:44
  • i am sorry . i forget to change column names. but it's not the key. because i just translate it to English Commented Nov 11, 2017 at 17:49

1 Answer 1

1

The first in your query is Unicode 0x1FFF rather than 0x3F00 (question mark). Try:

String sql = "Select Grade from XS_KC where Snum=? and Cnum=?";
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks sir. Maybe this is the sadness of people whose native language is not English

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.