private void fillCustomerInformationFields() throws SQLException {
Connection conn = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet;
Intent intent = getIntent();
String IDValue = intent.getStringExtra("id");
String query = "SELECT SiparisID, M.MusteriAdi + ' ' + M.MusteriSoyadi AS MusteriAdi, U.UrunAdi," +
" CASE WHEN OdemeTuru=0 THEN ? WHEN OdemeTuru=1 THEN ? WHEN OdemeTuru=2 THEN ? END AS OdemeTuru, TeslimTarihi,"+
"M.musteriAdresi, SiparisDurumu, Aciklama FROM Siparisler S INNER JOIN Musteriler M ON M.MusteriID=S.MusteriID INNER JOIN Urunler U ON U.UrunID=S.urunID"+
"WHERE S.SiparisID='"+IDValue+"'";
try {
conn = getDBConnection();
preparedStatement = conn.prepareStatement(query);
preparedStatement.setString(1,"Peşin");
preparedStatement.setString(2,"Taksitli");
preparedStatement.setString(3,"Kapıda");
resultSet = preparedStatement.executeQuery();
while(resultSet.next())
{
edtSiparisID.setText(resultSet.getString("SiparisID"));
edtUrunAdi.setText(resultSet.getString("UrunAdi"));
edtMusteriAdi.setText(resultSet.getString("MusteriAdi"));
edtOdemeTuru.setText(resultSet.getString("OdemeTuru"));
edtTeslimTarihi.setText(resultSet.getString("TeslimTarihi"));
edtSiparisAdresi.setText(resultSet.getString("musteriAdresi"));
edtAciklama.setText(resultSet.getString("Aciklama"));
}
}catch (SQLException e){
e.printStackTrace();
}finally {
if(preparedStatement != null){
preparedStatement.close();
}
if(conn != null){
conn.close();
}
}
}
大家好。我正在制作一个项目,我通过usb从android app连接到mssql。我写了代码从mssql读取数据,但我收到错误。我该如何修复错误?感谢您的帮助
LogCat中显示的异常是:
com.example.uur.stock W/System.err﹕ java.sql.SQLException: Incorrect syntax near 'S'.
答案 0 :(得分:1)
检查您的查询
String query = "SELECT SiparisID, M.MusteriAdi + ' ' + M.MusteriSoyadi AS MusteriAdi, U.UrunAdi," +
" CASE WHEN OdemeTuru=0 THEN ? WHEN OdemeTuru=1 THEN ? WHEN OdemeTuru=2 THEN ? END AS OdemeTuru, TeslimTarihi,"+
"M.musteriAdresi, SiparisDurumu, Aciklama FROM Siparisler S INNER JOIN Musteriler M ON M.MusteriID=S.MusteriID INNER JOIN Urunler U ON U.UrunID=S.urunID"+
"WHERE S.SiparisID='"+IDValue+"'";
这导致异常:
FROM Siparisler S JOIN Musteriler M
必须改为
FROM Siparisler as S JOIN Musteriler as M
更多信息: