简体   繁体   中英

Parameter index out of range (1 > number of parameters, which is 0)

I get this error, Can anyone help me in finding my mistake in the query?

public boolean populateLeagues(String leaguename, String password){

        Connect connect = new Connect();
        Connection conn = connect.Connection();
        Statement stmt = conn.createStatement();            
        String query = "INSERT INTO users VALUES('" + leaguename + "')";
        stmt.executeUpdate(query);
        conn.close();
}

AS @Jon Skeet says, use a prepared statement and inject parameters into. In this way you don't have to figure out all hassles about sql injection and data format(think about using a query like the one you provide to store datetime globally). Probably leaguename value is null . Remember that default value for string type isn't the empty strin but null

您在leaguename周围使用单引号,因为我们不知道leaguename的格式,这可能会导致错误

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