Zdravím. Mám problém s výpisom na displej. Moja aplikácia zobrazuje informácie z databázy. Funguje to na tom princípe, že načítam čiarový kód knihy a na displeji sa mi zobrazia info o knihe. Problém je v tom, že keď načítam kód s knihou, ktorá je v databáze všetko prebehne ok, ale hned potom ked skúsim načítať kód knihy, ktorá už v databáze nie je tak sa mi zobrazia tie isté info o predošlej knihe. Ak však načítam ako prvú knihu, ktorá nie je v databáze, zobrazí mi normálne hlásenie že kniha sa nenachádza v databáze. Dole je kód celého programu. Zrejme len bude problém s tým if kde riešim výpis že kniha nie je v databáze. Len neviem čo s tým. Ďakujem vopred za všetky rady.

Kód:
public class MainActivity extends Activity {
String url = "jdbc:jtds:sqlserver://XXXXX;instance=XXXXX;user=XXXXX;password=XXXXX";
String autor, nazov, vydavatelstvo, jazyk, edicia;
int rok, pocet_stran;
long isbn;
Connection con = null;
Statement st = null;
ResultSet rs = null;
String result = "", resultISBN = "";
Bundle dataMSSQL = new Bundle();
Bundle receive = new Bundle();
Message msg;
Handler MyHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
receive = msg.getData();
// Toast.makeText(getApplicationContext(), String.valueOf(msg.obj.toString()), Toast.LENGTH_LONG).show();
txtScanResult.setText(receive.getString("info"));
}
};
private Handler handler = new Handler();
private TextView txtScanResult;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity);
txtScanResult = (TextView) findViewById(R.id.scan_result);
View btnScan = findViewById(R.id.scan_button);
btnScan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
IntentIntegrator.initiateScan(MainActivity.this, R.layout.capture,
R.id.viewfinder_view, R.id.preview_view, true);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case IntentIntegrator.REQUEST_CODE:
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode,
resultCode, data);
if (scanResult == null) {
return;
}
resultISBN = scanResult.getContents();
if (resultISBN != null) {
handler.post(new Runnable() {
@Override
public void run() {
ResultSetMetaData rsmd = null;
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
con = DriverManager.getConnection(url);
st = con.createStatement();
rs = st.executeQuery("SELECT autor, nazov, vydavatelstvo, jazyk, edicia, rok, pocet_stran, isbn FROM zaznam "
+ "WHERE isbn="+resultISBN);
while(rs.next()){
autor = rs.getString("autor");
nazov = rs.getString("nazov");
vydavatelstvo = rs.getString("vydavatelstvo");
jazyk = rs.getString("jazyk");
edicia = rs.getString("edicia");
rok = rs.getInt("rok");
pocet_stran = rs.getInt("pocet_stran");
isbn=rs.getLong("isbn");
}
if(autor == null && nazov == null && vydavatelstvo == null && jazyk == null && edicia == null && rok == 0 && pocet_stran == 0 && isbn == 0)
result ="Kniha sa nenachádza v databáze";
else
result="\nAutor: "+ autor +
"\nNázov knihy: " + nazov +
"\nVydavateľstvo: " + vydavatelstvo +
"\nJazyk: " + jazyk +"" +
"\nEdícia: " + edicia +
"\nRok: " + rok +
"\nPočet strán: " + pocet_stran +
"\nISBN: "+isbn;
msg = Message.obtain();
dataMSSQL.putString("info",result);
msg.setData(dataMSSQL);
con.close();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
try {
MyHandler.sendMessage(msg);
} catch (Throwable t) {
}
}
});
}
break;
default:
}
}
}