SQL クエリの問題に直面しました。あなたの助けが必要です :(。私のコードでは、このコースの ID を入力するときに c#Log から学生の名前を表示したいのですが、これは c#Log テーブルです: HERE そしてこれはコース表です: HERE
これは私のコードです:
public void searchRows() throws ClassNotFoundException, SQLException
{
String logName=null;
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/psd_DB?"
+ "user=root&password=123");
Scanner s=new Scanner(System.in);
System.out.println("Enter the course id you want to display its log:");
courseId=Integer.parseInt(s.nextLine());
PreparedStatement st1 = (PreparedStatement) con.prepareStatement(" SELECT * FROM courses WHERE courseId="+courseId);
ResultSet r=(ResultSet) st1.executeQuery();
while(r.next())
{
logName=r.getString("courseName")+"Log";
}
//System.out.println(logName);
PreparedStatement st2 = (PreparedStatement) con.prepareStatement("SELECT "+logName+"."+"studentName FROM "+logName+" INNER JOIN courses ON "+logName+"."+courseId+"="+"courses."+courseId+";");
st2.executeQuery();
}
2 を入力すると、出力は次の例外になります。
スレッド「メイン」com.mysql.jdbc.exceptions.MySQLSyntaxErrorException での例外:「フィールド リスト」の列「C」が不明です