public void Deposite() throws Exception
{
try
{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/bank";
Connection con = DriverManager.getConnection(url,"root","admin");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your A/c no. : " );
acNo = Integer.parseInt(br.readLine());
String sql = "SELECT Name,Ac_No,Balance FROM CUSTOMER WHERE Ac_No=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(2,acNo);
ResultSet rs = ps.executeQuery();
while(rs.next())
{
String name = rs.getString("Name");
int acNo = rs.getInt("Ac_No");
float bal = rs.getFloat("Balance");
System.out.println(" "+name+" "+acNo+" "+bal);
}
i am getting this exception....plz help me...
error:
java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
You only have one Parameter to bind. Which has the index one:
So:
ps.setInt(2,acNo);
must be:
ps.setInt(1,acNo);