Making an update in database

Suppose I have these 3 classes:
class Student {
  private int m_intID;
  private String m_strName;
   public Student(int id, String n) {
// getters and setters
// toString ...
class DBStudent {
  // data members
  // methodes and functions
  public void updateStudent(int id, String name)  {
   try {
      // connection and update query ...
    } catch (SQLException sqle) {
      sqle.getMessage();
  public void updateStudent(Student studentSomeOne) {
    // update using studentSomeOne.getXXXXX ..
class Main {
  public static void main (String[] args) {
    Student studentJava = new Student ();
    DBStudent dbstudentJava = new DBStudent();
    // what is the best solution right here ??
   dbstudentJava.updateStudent(1784,"Roberto Carlos");
   // OR
   studentJava.setID (1784);
   studentJava.setNamen ("Roberto Carlos");
   dbstudentJava.updateStudent(studentJava);
}pleas read the comments :-) and tell me which one is the best solution and why ?
much thx in advance ...
Edited by: zJan on Dec 12, 2007 3:20 PM

If you're asking, "how do I store an object's state in a database?", then the answers are:
1) do it by hand using JDBC
2) use an object-relational mapping tool, like Hibernate.

Similar Messages

  • Problem in update to database

    Dear sir,
    I am making project on library management system using Netbeans 6.1
    in which i am able to connect my databases to the jtable in the frame sucessfully(jtable is used to display records of students who jahave issued the books) but when
    I peform update to database
    using following statements it gives me error that "no suitable driver found for java:derby:lib" in which lib is my database name.
    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                                String url = "jdbc:derby:lib";         try {               try {               Class.forName("org.apache.derby.jdbc.ClientDriver");             } catch (ClassNotFoundException ex) {                 Logger.getLogger(delUI.class.getName()).log(Level.SEVERE, null, ex);             }             Connection con = DriverManager.getConnection(url,"lib","lib");             java.sql.Statement stmt =  con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,                                     ResultSet.CONCUR_UPDATABLE);           ResultSet srs = stmt.executeQuery("delete * from student where sholarno="+jTextField2.getText());         } catch (SQLException ex) {             Logger.getLogger(delUI.class.getName()).log(Level.SEVERE, null, ex);         }       }                                               
    Also i observe that when I build the program the build is succesfull &
    there is one following statement written which says that it is not copying the libraries:
    D:\Program Files\glassfish-v2ur2\javadb\lib\derbyclient.jar is a directory or can't be read. Not copying the libraries.
    Building jar: C:\Documents and Settings\super\My Documents\NetBeansProjects\LibMan\dist\LibMan.jar
    Not copying the libraries.
    Sir, please help me to solve the above problem . Please tell me that it is not copying the files whether this causes the problem or anything is missing.

    The url listed is for an embedded Driver, but your loading the ClientDriver. So, which is it?

  • Updating different Databases Using XI

    Hello,
    I am having one requirement for updating different databases using XI.
    The scenario is that
    Data is coming from ERP to XI.
    This data should be inserted or updated in SQL server.
    Depending on certain conditions I need to update different SQL servers.
    Currently I am having one interface which updates one SQL server database.
    I want to change that interface for updating different SQL server databases depending on the data coming from ERP.
    Is it possible?
    How can I achieve this?
    Thanks in Advance
    Abhijit.

    Hi abi,
        For using more than one database server u can use the BPM.
        there in the design phase, while u making the layout of the picture type connection , there in the switch tool , u can put the condition and according to that
    it will connect to the database server.......
    if it is useful give the rewards
    Regards
    Sasi.........

  • Esitable alv, n update in database

    HI Experts,
    How to make an Editable ALV, and if i changed the field content that should update in database. can you give me a solution thru function modules and oops concepts.

    Hi,
    Making a particular field editable is pretty straight forward.
    Just put edit = 'X' while preparing your fieldcatalog.
    But then capturing the edited values and updating into the table is a bit tricky.
    You need to catch the event of enter press and then check where you get the edited value.
    I am also not 100% clear with this updation part.
    Hope it helps.
    Regards,
    Siddhesh S.Tawate

  • Error while updating a database

    hi,
    i am getting an error "Object reference not set to an instance of object" while updating a database. here is my code..
    QryStr = "update OSRI set U_sqf = Val('" & sqft & "'),U_sqm = Val('" & sqmt & "') where ItemCode = '" & Code & "'"
                RecSet.DoQuery(QryStr)
                Res = True
    Edited by: puneeth shankar on Jul 2, 2008 7:27 PM

    Hi
    Maybe you are missing these sentences ..
    Dim RecSetAs SAPbobsCOM.Recordset
    RecSet= SBO_Company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
    and then
    QryStr = "update OSRI set U_sqf = Val('" & sqft & "'),U_sqm = Val('" & sqmt & "') where ItemCode = '" & Code & "'"
    RecSet.DoQuery(QryStr)
    Res = True
    But I think you are trying to update directly using an Update statement to a SAP table.  You must check the documentation.  I think this is not allow.  You must then use an alternate way !

  • TS3694 I was making the update for my iphone 4s . then he stops. My phone in this time is in the recovery mode and do not take the firmware to open my phone, please can u help me to recover my phone. My current  ios 6.0.1. plese send me some thing that is

    was making the update for my iphone 4s . then he stops. My phone in this time is in the recovery mode and do not take the firmware to open my phone, please can u help me to recover my phone. My current  ios 6.0.1. plese send me some thing that is useful

    Thanks for that 'sberman' - because my iPhone is backed-up to my work computer (only at this stage) I have had to call our IT Department in Adleaide. (4 times this morning). The last guy managed to get the phone into 'DFU Mode' - no more recovery mode screen - (kind of 'asleep' perhaps) from my understanding of same. I am awaiting a call again from IT so they can get my computer to actually recognise my iPhone on the C Drive. This also happened to  one of my colleagues in Newman (WA). She got so frustrated with the whole process that she bought another phone the next time she was in 'civilisation.' She hasn't had any problems since. (Cross fingers).
    Thanks again, Sandra2474.

  • How to change the profile value in the pl/sql code without making change in the database

    How to change the profile value in the pl/sql code without making change in the database.

    I have program ,where if the profiles 'printer and nunber of copies ' are set at the user level, by default when the report completes the O/p will be sent to the printer mentioned in the set-up. but what user wants is
    if these Profiles are set for the user running this program automatic printing should not be done.

  • Regardig error while updating the database table

    hi experts,
       i m trying to update the database table from the values containig in my internal table  ,,,but the system is giving this error plz help me::::
    The type of the database table and work area (or internal table)
    "ITAB_UPDATE" are not Unicode convertible. Unicode convertible.          
    my internal table name itab_update and the database table name yitab.i m using this statement::
        modify yitab from itab_update.

    Hi
    1. You  have to Declare the Itab with the same structure as DB table.
    2. Use the statement
        Modify <DBtable> from TABLE <itab>.
    or
       Update <DBtable> from TABLE <itab>.
    Hope this will solve.
    Reward .....if so.
    Regards.

  • Problem while updating a database table

    Hi experts,
                         I've used the FM 'HR_INFOTYPE_OPERATION' to update the database table. In that i used the MOD operation to update the Infotype PA0315.  But it return an error message like "Infotype does not exist". What could be the reason for this error?.
    regards,
    Shanthi.

    Hi,
          Here is my code for updation.
    CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'
    EXPORTING
    NUMBER = P0315-pernr
    IMPORTING
    RETURN = wf_returne.
    Update Mode
    CALL FUNCTION 'HR_INFOTYPE_OPERATION'
    EXPORTING
    INFTY = '0315'
    NUMBER = P0315-PERNR
    SUBTYPE = P0315-SUBTY
    OBJECTID = P0315-OBJPS
    LOCKINDICATOR = P0315-SPRPS
    VALIDITYEND = P0315-ENDDA
    VALIDITYBEGIN = P0315-BEGDA
    RECORDNUMBER = P0315-SEQNR
    RECORD = P0315
    OPERATION = 'MOD'
    TCLAS = 'A'
    DIALOG_MODE = '0'
    IMPORTING
    RETURN = wf_return.
    Dequeue
    CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE'
    EXPORTING
    NUMBER = P0315-PERNR.

  • Problem viewing/updating MySQL-database with utf-8 charset

    System specs:
    Tomcat 5.5.4
    JDK1.5.0
    MySQL 4.1
    Connector/J 3.0.16
    JSTL 1.1
    I am trying to build a guestbook web-app, and want to be able to store swedish characters (available in latin1) and decided to give utf-8 a go since it would support other languages as well. I use a <Resource> in my context-xml to get the connection.
    This simply will not work; when I use the <%@ page contentType="text/html; charset=utf-8"%> declaration, the swedish characters in the raw html-code gets replaced by questionmarks. Select-queries output look ok though, as long as they don't contain the character '�'
    When removing the page-declaration, the queries show only questionmarks where swedish characters should be.
    The same goes for updating my database. Swedish characters get garbled.
    I have tried the following without success:
    *adding &useUnicode=true&characterEncoding=UTF-8 to the Resource-url -- causes my web-app to fail loading.
    *adding a <filter> to the web-apps web.xml as suggested at  http://www.javaworld.com/javaworld/jw-09-2004/jw-0906-unicode_p.html -- caused another web-app error, resulting in it not being loaded.
    *setting the form attribute accept-charset -- resulted in no improvement.
    Right now I'm half desperate and half fed-up. Is this a common problem with MySQL? Should I use another database? Or perhaps it is the Connector/J Driver that's messing things up.
    I'll appreciate any help I get greatly.

    Hello. Maybe not so interesting after a year to try to ask did you ever get a final solution to that problem in command line perspective. OR does somebody else knows solution to this problem.
    Anyway I have similar problem, I use mysql5 with latin1 charset and I can insert to my database letters ��� normally via mysql command line and they show perfectly. But the problem is my web application.
    I can insert all characters to database and retrieve them normally via web app but if i need to use mysql command line for queries it fails because those special letters appear something like ��. I still need to make queries on mysql command line as admin. I have also tried to change different drivers like
    Class.forName("org.gjt.mm.mysql.Driver"); or
    com.mysql.jdbc.Driver etc connector is 3.0.17
    I have also tried to change to utf-8 and then changed mysql def.enc to same... i have used request.setWHATEVER CHARSET.....i'm out of ideas... help?

  • Lion Mail will not open, and won't update the database. Help??

    When I try to open mail, for the first time says it needs to update my database, It seems to start then crashes. Is there a fix?

    same here, updated all devices, moved to icloud, received mail for a bit now NOTHING. no mail, no backup, won't accept my password......service must be down???

  • Data not updating in database

    Friends i have table and i have created a sequence on basis of that table.
    For 1st page i have created an html region and made few items there and a save button.
    I am filling data to the fields in page 1 and clicking the save button. In save button i have passed the address of the items of 1st page to items of 2nd page which contains the same field of page 1 and few more additional field.
    the 2nd page which i have made is on basis of form on a table or view and taken exsisting sequence there. When i clicking the submit button in page 2 it is not updating my database and throwing error called unable to fetch row. Any suggestions on this?

    Lev addition to this i wanted when my create button in 2nd page get clicks my database gets updated and also a query runs which checks the same data of combination variant_type,model_code,year_manuafacture. It means if i have 2 records in database with same variant_type,model_code,year_manufacture then in the field how_many in page 2 count of 3 gets updated and the other field solution avaiable get updated with Y.
    For this in my local system in page 2 i created a plsql process and wrote this code and applied it with create button but its not working. Any idea where i am failing?
    Declare
    l_how_many Number;
    l_sol_av Varchar2(1):= NULL;
    Begin
    select count(*)
    into l_how_many
    from quality
    where 1=1
    and variant_type= :P2_VARIANT_TYPE --'Road Bike'
    and model_code = :P2_MODEL_CODE --'6'
    and year_manufacture= :P2_YEAR_MANUFACTURE  ; --'2000'
    If l_how_many=null then
        l_sol_av := 'N' ;
    else
        l_sol_av := 'Y';
    end If ;
    :P2_SOLUTION_AVAILABLE := l_sol_av;
    :P2_HOW_MANY_RAISED       := l_how_many;
    Exception
        when no_data_found then
        null;
    end;

  • How to capture the Escalation status in Human Task & Update in database

    Hi,
    I have created a Workflow where I have a humantask. Here if the Approver Escalates the task, I want to capture this Workflow status and need to Update it in the our(Oracle) Database as Escalated. I am Updating the database as Approved when the Approver Approves and Rejected when he rejects. as we can have capture these status. Similarly I want to do for the Escalated status also.
    Please Help I have been stuck to this.
    Thanks.

    No Experts to answer this???????????????????

  • New ABAP Program to check Direct UPDATE in Database Table

    Hi all,
    As per customer requirement , I have to develop ONE  Program which find out that  in which ABAP Program , Programmer has used Open Sql command like  UPDATE , DELETE , INSERT , MODIFY to direct update in Database Table.
    Have a look on all Z-ABAPs, find out if there are statements with "update", "delete", "insert" or "modify" in the coding, then find out if updates to sap-Tables are done
    How can I achived that ?
    Please , If anybody is having idea , than please let me know..
    Thanks You ,

    Hi
    Kindly refer to the below link. This has step by step how you can achieve the checks.
    [http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/12659a90-0201-0010-c18b-9d014f9bed0d]
    But if you want to check if any program they have used 'UPDATE' then you can do like below.
    Go to SE38
    Utilities---> Find in Source Code-
    Find --- UPDATE
    In program - Z* or ZX* if you want to search only in Exits
    Regards,
    Vijay V .

  • Updating a database using EJB Inheritance

    I am new to EJB's, so please forgive my ignorance. I creating the following classes that inherit from each other along with a method to update my database:
    @Entity
    @Inheritance(strategy = InheritanceType.JOINED)
    @DiscriminatorColumn(name="TYPE", discriminatorType=DiscriminatorType.STRING)
    public abstract class ObjectA implements java.io.Serializable {
         protected String name;
         protected String desc;
         protected String type;
    @Entity
    @DiscriminatorValue("OBJECTB")
    public class ObjectB extends ObjectA implements java.io.Serializable {
         protected String str_b;
         public ObjectB(String name, String desc, String type, String str_b) {
              this.name = name;
              this.desc = desc;
              this.type = type;
              this.str_b = str_b;
    @Entity
    @DiscriminatorValue("OBJECTC")
    public class ObjectC extends ObjectB implements java.io.Serializable {
         private String str_c;
         public ObjectC(String name, String desc, String type, String str_b, String str_c) {
              this.name = name;
              this.desc = desc;
              this.type = type;
              this.str_b = str_b;
              this.str_c = str_c;
    public class MyFacade implements ServletContextListener {
         @PersistenceUnit(unitName="Pu")
        private EntityManagerFactory emf;
        @Resource
        private UserTransaction utx;
        public MyFacade() { }
        public void contextDestroyed(ServletContextEvent sce) {
            if (emf.isOpen()) emf.close();
        public void contextInitialized(ServletContextEvent sce) {
            ServletContext context = sce.getServletContext();
            context.setAttribute("MyFacade", this);
         public void updateObject(ObjectA obj) {
            EntityManager em = emf.createEntityManager();
            try{
                utx.begin();
                em.merge(obj);
                utx.commit();
            } catch(Exception exe){
                try {
                    utx.rollback();
                } catch (Exception e) {}
                throw new RuntimeException("Error updating obj", exe);
            } finally {
                em.close();
    }If I do the following:
         String name = "test name";
         String desc = "updating object c";
         String type = "OBJECTC";
         String b = "b";
         String c = "c";
         MyFacade myf = new MyFacade();
         ObjectC objC = new ObjectC(name, desc, type, b, c);
         myf.updateObject(objC);
         .....In my database, only the values associated with ObjectC get updated and nothing from ObjectA or ObjectB get updated in the database. Does the "merge" method not work on inheritance. How do I update my database using inheritance?
    Thanks!
    Message was edited by:
    FourierXForm

    did you only have ISQL for testing it?
    Can you debug the form and look, if someone happens - exceptions, ... ?
    after the update you can use
    message (SQL%ROWCOUNT); pause ;
    to look, how many records were updated

Maybe you are looking for

  • Indesign CC: the shortcut «Align left --- Default: Shift+Cmd+L» seems not working...

    Under any keyboard combination: default, proper, PM, Quark The Indesign label in the menu (above, left) is shadowed when the shortcut is typed. But the rest of them are oK Shift+Cmd+R Shift+Cmd+C Shift+Cmd+J Shift+Cmd+F Could be fixed in some way? Ju

  • Error - Cannot connect to the phone

    Hi all, have had a dig around and couldn't find anything so I hoping that someone can sort me out here. Ok I have my phone connected to the pc via bluetooth. PC Suite picks up the phone but when I click on the Contacts or Messages (or anything in tha

  • Auto check spell check error

    I have a bad habit of typing THE as TEH, usually the auto spell check pick this up. Recently the auto spell check doesn't pick up the TEH spelling mistakes. This applies to all text programs, none of them detect this specific spelling error. Any idea

  • What size for Time Machine

    Hi, I am backing up my iMac to a WD Mybook with 500 Go space. The iMac hard drive has 235 Go on it right now. I have been backing up with TM since June and the Mybook is now full. Is this normal? I seem to remember before, TM did not take up so much

  • AP signal strength

    Hi All, How to get the received signal strength of an access point. Is there is any command?. I have 2 APs in bridge mode. I know the transmitted power (100 mw). I am getting intermittent link failure. To analysis the problem I need to know the recei