1
import java.sql.*;

class TestConnection 
{
public static void main(String args[])
{

    try
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:ram","myuser","myuser");

        Statement st = con.createStatement();
        st.executeUpdate("insert into student values( &stno, &sname, &course, &fees); ");
        System.out.println("1 row Inserted");

        con.close();
    }
    catch(Exception P)
    {
        P.printStackTrace();
    }
}

}

i have already created table, and i want to enter the input from keyboard, but i am getting the following error please help me.......

java.sql.SQLException: [Oracle][ODBC][Ora]ORA-01008: not all variables bound
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source)
at TestConnection.main(TestConnection.java:13)

1 Answer 1

1

You should use the PreparedStatement and set the parameters as follows:

import java.sql.*;

class TestConnection 
{
    public static void main(String args[])
    {
        int stno = Integer.parseInt(args[0]);
        String name = args[1];
        String course = args[2];
        double fees = Double.parseDouble(args[3]);

        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = 
                DriverManager.getConnection("jdbc:odbc:ram","myuser","myuser");
            PreparedStatement st = 
                con.prepareStatement("insert into student values(?, ?, ?, ?)");
            st.setInt(1, stno);
            st.setString(2, name);
            st.setString(3, course);
            st.setDouble(4, fees);
            // executeUpdate returns the number of rows inserted/updated/deleted.
            int count = st.executeUpdate();
            System.out.println(count + " row(s) inserted.");
            con.close();
        }
        catch(Exception P)
        {
            P.printStackTrace();
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

You have to run it as java TestConnection 1 fastnto Algorithms 500.

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.