welshspoon
Technical User
Hiya
I am trying to carry out a query on a MySQL database and output the results as single records which can be scrolled through on a JPanel. However, when executed the code I get
SELECT q.Question, q.AnswerOne, q.AnswerTwo, q.AnswerThree, q.AnswerFour FROM te
st t, questionbank q WHERE t.? = q.QuestionID
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Q
uestionOne' = q.QuestionID' at line 1
The code I have written is shown below
Thanks in advance
I am trying to carry out a query on a MySQL database and output the results as single records which can be scrolled through on a JPanel. However, when executed the code I get
SELECT q.Question, q.AnswerOne, q.AnswerTwo, q.AnswerThree, q.AnswerFour FROM te
st t, questionbank q WHERE t.? = q.QuestionID
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Q
uestionOne' = q.QuestionID' at line 1
The code I have written is shown below
Code:
try {
// Load the JDBC driver
String driverName = "org.gjt.mm.mysql.Driver"; // MySQL MM JDBC driver
Class.forName(driverName);
// Create a connection to the database
String serverName = "localhost";
String mydatabase = "project";
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "root";
String password = "Password";
con = DriverManager.getConnection(url, username, password);
} // end try
catch (java.lang.Exception ex) {
ex.printStackTrace();
}
ResultSet rs = null;
try{
// String data = "QuestionOne";
if (QueryStmt == null) {
String Query = "SELECT q.Question, q.AnswerOne, q.AnswerTwo, q.AnswerThree, q.AnswerFour FROM test t, questionbank q" + " WHERE t.? = q.QuestionID";
System.out.println(Query);
QueryStmt = con.prepareStatement("SELECT q.Question, q.AnswerOne, q.AnswerTwo, q.AnswerThree, q.AnswerFour FROM test t, questionbank q" + " WHERE t.? = q.QuestionID");
}
QueryStmt.setString(1,"QuestionOne");
rs = QueryStmt.executeQuery();
while(rs.next()) {
}
} // end try
catch (java.lang.Exception ex) {
ex.printStackTrace();
}
Thanks in advance