java sql SQLException Missing IN or OUT parameter at index 1

0 votes

Using OJDBC 6, I created some Java 1.6-Oracle11g-JDBC code (below). I'm being given an exception:java.sql.SQLException: Missing IN or OUT parameter at index:: 1 . How can I stop this from happening and why?

My output is-

create CREATE TABLE employee(emp_name varchar(25),emp_address varchar(25))
insert INSERT INTO employee(jim,germany) values(?,?)
Exception: java.sql.SQLException: Missing IN or OUT parameter at index:: 1

The code is-

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;


public class Oracle {

public static void main(String[]args)
{

    try
    {

        Connection con = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/xe", "newman", "123456");
        Statement stmt = con.createStatement(); 

        String create = "CREATE TABLE employee(emp_name varchar(25),emp_address varchar(25))";
        System.out.println("create " + create);//
        stmt.execute(create);

        //insert 1st row            
        String inserting = "INSERT INTO employee(hans,germany) values(?,?)";
        System.out.println("insert " + inserting);//
        PreparedStatement ps = con.prepareStatement(inserting); 
        ps.executeUpdate();

        //insert 2nd row            
        inserting = "INSERT INTO employee(david,austria) values(?,?)";
        System.out.println("insert " + inserting);//
        ps = con.prepareStatement(inserting); 
        ps.executeUpdate();

    }catch(SQLException ex){System.out.println("Exception: " + ex);}


    }

}

To correct the code, I used:

//insert 1st row

        String inserting = "INSERT INTO 
                    employee(emp_name,emp_address) values(?,?)";
        PreparedStatement ps = con.prepareStatement(inserting);
        System.out.println("insert " + inserting);//
        ps.setString(1, "hans");
        ps.setString(2, "germany");
        ps.executeUpdate();

//insert 2nd row

        inserting = "INSERT INTO 
                    employee(emp_name,emp_address) values(?,?)";
        ps = con.prepareStatement(inserting);
        System.out.println("insert " + inserting);//
        ps.setString(1, "david");
        ps.setString(2, "austria"); 
        ps.executeUpdate();
Aug 15, 2022 in Database by Kithuzzz
• 38,020 points
6,537 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Database

0 votes
0 answers
0 votes
1 answer

java.sql.SQLException: Column count doesn't match value count at row 1

I think PreparedStatement would be a better choice. I ...READ MORE

answered Sep 20, 2022 in Database by narikkadan
• 63,680 points
2,108 views
0 votes
1 answer

IN vs OR in the SQL WHERE Clause

I assume you want to know the ...READ MORE

answered Sep 24, 2018 in Database by DataKing99
• 8,250 points
3,892 views
0 votes
1 answer

Difference between clustered and non clustered index in SQL

The differences between the clustered and non ...READ MORE

answered Sep 28, 2018 in Database by Sahiti
• 6,370 points
1,802 views
0 votes
1 answer

How to detect a SQL table's existence in Java?

Hello, Depending on the DB, you can do ...READ MORE

answered May 13, 2020 in Database by Niroj
• 82,880 points
934 views
0 votes
1 answer

What is an index in SQL?

An index is used to speed up ...READ MORE

answered Feb 3, 2022 in Database by Vaani
• 7,070 points
650 views
0 votes
1 answer

How to retrieve column names from java.sql.ResultSet?

You may refer the below code: ResultSet ...READ MORE

answered Jul 4, 2018 in Java by sophia
• 1,400 points
2,827 views
0 votes
1 answer

Establish JDBC Connection in R through single sign-on

You can certainly connect to databases with ...READ MORE

answered Sep 12, 2018 in AWS by Priyaj
• 58,100 points
2,458 views
0 votes
1 answer

Find Oracle JDBC driver in Maven repository

Download the jar and place it in ...READ MORE

answered Sep 26, 2018 in Java by Daisy
• 8,140 points
3,252 views
0 votes
1 answer

Accessing connection from different class in Java / MySQL?

You should just instantiate DoComms with every ...READ MORE

answered Nov 14, 2018 in Database by nirvana
• 3,130 points
1,910 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP