I have been breaking my head with this code for too long now. I am trying to insert data into an msaccess data base here's what my code looks like:import java.sql.*;
public class InsertCoffees
{
public static void main(String args[])
{
String url = "jdbc:odbc:Noorderwind";
int i = 0050;
String var1 = "Columbian";
float var2 = 7.9f;
int var3 = 0;
int var4 = 0;
Connection con;
Statement stmt;
String query = "select COF_NAME, PRICE from COFFEES";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try
{
con = DriverManager.getConnection(url);
stmt = con.createStatement();
stmt.executeUpdate("insert into COFFEES values('$var1', '$i', '$var2', '$var3', '$var4')");//here lies the problem, the parameters are not getting passed in..I think it is because of the way i have declared them..how else should i declare them or pass them as arguements??
stmt.executeUpdate("insert into COFFEES values('French_Roast', 00049, 8.99, 0, 0)");
stmt.executeUpdate("insert into COFFEES values('Espresso', 00150, 9.99, 0, 0)");
stmt.executeUpdate("insert into COFFEES values('Colombian_Decaf', 00101, 8.99, 0, 0)");
stmt.executeUpdate("insert into COFFEES values('French_Roast_Decaf', 00049, 9.99, 0, 0)");
ResultSet rs = stmt.executeQuery(query);
System.out.println("Coffee Break Coffees and Prices:");
while (rs.next())
{
String s = rs.getString("COF_NAME");
float f = rs.getFloat("PRICE");
System.out.println(s + " " + f);
}
stmt.close();
con.close();
}
catch(SQLException ex)
{
System.err.println("SQLException: " + ex.getMessage());
}
}
}
thanks a bunch,
I will appreciate your help very immensely.
Akansha