0

こんにちは、小さな問題があります。テーブルを切り替えて結果を取得するにはどうすればよいですか?? 以下のコードは機能していません。助けてくれてありがとう

String typelogin=null;
if(xx){
   typelogin="users_table";
}else{
   typelogin="admin_table";
}
String sqlStr = "Select * from "+typelogin+" where username=? and userpassword=?";
PreparedStatement stmt = conn.prepareStatement(sqlStr);

完全なコード:

Statement stmt = conn.createStatement();

            String sqlStr = "Select * from "+typelogin+" where username=? and userpassword=?";


            PreparedStatement pstmt=conn.prepareStatement(sqlStr);
            pstmt.setString(1,user);
            pstmt.setString(2,password);
            //step 6 Process result
            ResultSet rs = pstmt.executeQuery();

私が得ているエラー:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'fromspmovy_admin where username='abc' and userpassword='abc'' at line 1

回答[解決済み]:

空白を入れ忘れた

from " + typelogin + " where
4

2 に答える 2

3

エラー メッセージから:とテーブル名'fromspmovy_admin where ...の間の空白を逃したようです。fromすべてのメソッドでこれを正しい方法で行っていることを確認してください (現在の例ではこれは起こらないことに注意してください)。

于 2013-07-25T16:05:42.447 に答える