ResultSet to Int [modified]
-
How to convert ResultSet to Integer? i do it this way however i encountered errors. codes as follows:
rs = stmt.executeQuery("Select count(1) from INCIDENTDATA where INCIDENTID = 10"); Integer id = rs.getInt(1); if( id == 0){ . . . }
When i do a debug errors i encounted: 1. "id" is not a known variable in the current context.; 2. "rs" is not a known variable in the current context.; http://img841.imageshack.us/img841/1965/exeerror.png[^] needing help. When i execute the SQL this is the screen shot : http://img502.imageshack.us/img502/8532/executey.png[^] how do i get the value 0 so as to compare it if it is 0 then i will add the value 10 into the database?
modified on Sunday, January 16, 2011 11:25 PM
-
How to convert ResultSet to Integer? i do it this way however i encountered errors. codes as follows:
rs = stmt.executeQuery("Select count(1) from INCIDENTDATA where INCIDENTID = 10"); Integer id = rs.getInt(1); if( id == 0){ . . . }
When i do a debug errors i encounted: 1. "id" is not a known variable in the current context.; 2. "rs" is not a known variable in the current context.; http://img841.imageshack.us/img841/1965/exeerror.png[^] needing help. When i execute the SQL this is the screen shot : http://img502.imageshack.us/img502/8532/executey.png[^] how do i get the value 0 so as to compare it if it is 0 then i will add the value 10 into the database?
modified on Sunday, January 16, 2011 11:25 PM
I have made changes to the codes. Right now i dont face any error but however i dont see the value that i have added, being added to the table.
public String add_btn_action() throws SQLException {
ResultSet rs = null;
Statement stmt = null;Integer id; String dbURL = "...."; String incidentId = (String) getIncidentidtxt().getValue(); Integer incidentIntId = Integer.parseInt(incidentId); String incidentName = (String) getIncidentnametxt().getValue(); Connection con = DriverManager.getConnection(dbURL); try{ stmt = con.createStatement(); rs = stmt.executeQuery("Select COUNT(1) from INCIDENTDATA where INCIDENTID = "+incidentIntId+""); while(rs.next()){ id = rs.getInt(1); if( id == 0){ getSessionBean1().updateIncident(incidentIntId, incidentName); incidentdataDataProvider.refresh(); } else{ Integer newIncidentID = incidentIntId + 1; getSessionBean1().updateIncident(newIncidentID, incidentName); instancedataDataProvider.refresh(); } } } catch(Exception e){ e.getMessage(); } return null; }
Needing help..
-
I have made changes to the codes. Right now i dont face any error but however i dont see the value that i have added, being added to the table.
public String add_btn_action() throws SQLException {
ResultSet rs = null;
Statement stmt = null;Integer id; String dbURL = "...."; String incidentId = (String) getIncidentidtxt().getValue(); Integer incidentIntId = Integer.parseInt(incidentId); String incidentName = (String) getIncidentnametxt().getValue(); Connection con = DriverManager.getConnection(dbURL); try{ stmt = con.createStatement(); rs = stmt.executeQuery("Select COUNT(1) from INCIDENTDATA where INCIDENTID = "+incidentIntId+""); while(rs.next()){ id = rs.getInt(1); if( id == 0){ getSessionBean1().updateIncident(incidentIntId, incidentName); incidentdataDataProvider.refresh(); } else{ Integer newIncidentID = incidentIntId + 1; getSessionBean1().updateIncident(newIncidentID, incidentName); instancedataDataProvider.refresh(); } } } catch(Exception e){ e.getMessage(); } return null; }
Needing help..
A good place to start would be with the on-line JDBC tutorials: http://java.sun.com/products/jdbc/learning.html[^] http://download.oracle.com/javase/tutorial/jdbc/index.html[^]
-
A good place to start would be with the on-line JDBC tutorials: http://java.sun.com/products/jdbc/learning.html[^] http://download.oracle.com/javase/tutorial/jdbc/index.html[^]
-
I have made changes to the codes. Right now i dont face any error but however i dont see the value that i have added, being added to the table.
public String add_btn_action() throws SQLException {
ResultSet rs = null;
Statement stmt = null;Integer id; String dbURL = "...."; String incidentId = (String) getIncidentidtxt().getValue(); Integer incidentIntId = Integer.parseInt(incidentId); String incidentName = (String) getIncidentnametxt().getValue(); Connection con = DriverManager.getConnection(dbURL); try{ stmt = con.createStatement(); rs = stmt.executeQuery("Select COUNT(1) from INCIDENTDATA where INCIDENTID = "+incidentIntId+""); while(rs.next()){ id = rs.getInt(1); if( id == 0){ getSessionBean1().updateIncident(incidentIntId, incidentName); incidentdataDataProvider.refresh(); } else{ Integer newIncidentID = incidentIntId + 1; getSessionBean1().updateIncident(newIncidentID, incidentName); instancedataDataProvider.refresh(); } } } catch(Exception e){ e.getMessage(); } return null; }
Needing help..
-
pancakeleh wrote:
Right now i dont face any error but however i dont see the value that i have added, being added to the table.
You would of course need to write code that does in fact do an update to the table.
I have written a method in sessionBean named updateIncident for adding the values to the database. the codes as follows:
public void updateIncident(Integer incidentIDName, String incidentNameName){ incidentdataDataProvider.refresh(); //Set new row RowKey rkUpdate = incidentedataDataProvider.appendRow(); //Move to new created row incidentdataDataProvider.setCursorRow(rkUpdate); //Set Input incidentdataDataProvider.setValue("INCIDENTDATA.INCIDENTID", incidentIDName); incidentdataDataProvider.setValue ("INCIDENTDATA.INCIDENTNAME", incidentNameName); incidentdataDataProvider.refresh(); }
-
I have written a method in sessionBean named updateIncident for adding the values to the database. the codes as follows:
public void updateIncident(Integer incidentIDName, String incidentNameName){ incidentdataDataProvider.refresh(); //Set new row RowKey rkUpdate = incidentedataDataProvider.appendRow(); //Move to new created row incidentdataDataProvider.setCursorRow(rkUpdate); //Set Input incidentdataDataProvider.setValue("INCIDENTDATA.INCIDENTID", incidentIDName); incidentdataDataProvider.setValue ("INCIDENTDATA.INCIDENTNAME", incidentNameName); incidentdataDataProvider.refresh(); }
thanks but where should u put all this code(mean to put it inside the try and catch or where...)