I would like to request you all out there to help me out solve this problem. Your valuable inputs are very helpful. i have this program which prompts the user for firstname and lastname and stores the data in a MSAccess DataBase. I am getting an error when i run my code. The error is somehow confusing because it needs only one parameter which doesnt make sense to me.
Here's the error:
C:\JAVA2>java SimpleJdbc
Enter the first name:mary
Enter the last name:allen
Driver loaded
Database connected
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few paramet
ers. Expected 1.
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 SimpleJdbc.main(SimpleJdbc.java:33)
Here's my code:
import java.sql.*;
import java.util.*;
public class SimpleJdbc {
public static void main(String[] args)
throws SQLException, ClassNotFoundException {
Scanner input = new Scanner(System.in);
String FName = "", LName ="";
System.out.print(" Enter the first name:");
FName = input.next();
System.out.print(" Enter the last name:");
LName = input.next();
// Load the JDBC driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver loaded");
try{
// Establish a connection
Connection connection = DriverManager.getConnection
("jdbc:odbc:JUMAWIND");
System.out.println("Database connected");
// Create a statement
Statement statement = connection.createStatement();
// Execute a statement
statement.executeUpdate(" INSERT INTO Student(firstname,lastname)" +
"VALUES(" + FName + ", '" + LName +"')");
// Close the connection
}
catch (SQLException ex) {
ex.printStackTrace();
}
}
}
As you can see, there is NO connection or loading problem. The only problem is in the syntax. I would appreciate your feedback.
Thanx, Allen.

New Topic/Question
Reply



MultiQuote



|