I am new to Java Swing programming, so please bear with me.
I have connected my JFrame
to MA Access data base using JDBC ODBC driver and here is the erroneous code.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:MS Access Database");
st = con.createStatement();
String q = "select "+Name+",Date/Subject from "+$Class;
R = st.executeQuery(q);
int row=0;
while(R.next())
{
Table.setValueAt(R.getString("Date/Sujbect"),row,0);
Table.setValueAt(R.getString(Name),row,1);
row++;
}
when the st.executeQuery(q)
is reached, it throws an exception saying.
"Too few Parameters. Expected 2".
What I don't understand is this: when the query is written like
"select * from "+ $Class;
it works perfectly fine. Even in some other JFrame
s, I am doing the same thing. This exception persists as log as I mention the exact columns instead of the star(*).
Please also let me know if there is any workaround this, or any other method that I may use.