When I run the following code I am getting this error... please can someone advise. (I have a similar question in the database section of the forum but there are significantly fewer users looking there!)
Thanks
ERROR
My database setup is as followsCode:SQL StatementSELECT English FROM smsdb1 WHERE SMS = ?
Prepared Statementorg.sqlite.PrepStmt@199a0c7c
Prepared Statementorg.sqlite.PrepStmt@199a0c7c
java.sql.SQLException: no such column: 'id'
at org.sqlite.RS.findColumn(RS.java:116)
at org.sqlite.RS.getString(RS.java:247)
at PreparedStatementParameter.main(PreparedStatementParameter.java:26)
Attachment 2102
Code:import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class PreparedStatementParameter {
public static void main(String[] args) {
Connection conn = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:C:\\smsdb1.sqlite");
String sqlStmt = "SELECT English FROM smsdb1 WHERE SMS = ?";
System.out.println("SQL Statement" + sqlStmt);
prepStmt = conn.prepareStatement(sqlStmt);
System.out.println("Prepared Statement" + prepStmt.toString());
prepStmt.setString (1, "2nite");
System.out.println("Prepared Statement" + prepStmt.toString());
rs = prepStmt.executeQuery();
while (rs.next()) {
String id = rs.getString("id");
String English = rs.getString("English");
System.out.println("Translation: " + id + ", Proper English: " + English );
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (prepStmt != null)
prepStmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null)
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}

