Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Error--> [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1

 
Gaurav Pavan Kumar Jain
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find the code of program.

import java.io.*;
import java.sql.*;

public class NewTest
{

public NewTest()
{
}


public void enter_Data()
{
Connection con=null;
try
{
// Load Driver class

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


// Create Odbc Connection

con=DriverManager.getConnection("jdbcdbc:test","","");

// Create Statement
Statement stat=con.createStatement();

// Insert Data in database
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Name:-");
String name=bf.readLine();
stat.executeUpdate("INSERT INTO jav " + "VALUES (name)");
}

catch (Exception Ex)
{
System.err.println("Error/Exception"+Ex.getMessage());
}


finally
{
try
{
if(con !=null)
{
con.close();
}
}

catch(SQLException se)
{
System.out.println("SQL Exception");
}
}
}

public static void main(String args[])
{
NewTest obj=new NewTest();
obj.enter_Data();
}
}

I am trying to insert data in database from console at run time but it genrate error---> [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

Please help me.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use CodeTags

And problem is in this line:

Are you sure that "name" value is being pass to the statement ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic