Jdbc...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • malathi krishna
    New Member
    • Aug 2007
    • 8

    Jdbc...

    Hi,

    When iam working with JDBC, i tried to update the database table through updateStirng() method through java program...

    The string is getting inserted but the problem is it is getting stored in AlphaNumeric format...

    Can anyone help me in sorting out this...Why is this happening so????

    ThankYou,
    Malathi.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by malathi krishna
    Hi,

    When iam working with JDBC, i tried to update the database table through updateStirng() method through java program...

    The string is getting inserted but the problem is it is getting stored in AlphaNumeric format...

    Can anyone help me in sorting out this...Why is this happening so????

    ThankYou,
    Malathi.
    What do you mean by "it is getting stored in AlphaNumeric format..."?
    Can you give us an example of what is happening? Also post the code you're using for inserting the string.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by malathi krishna
      Hi,

      When iam working with JDBC, i tried to update the database table through updateStirng() method through java program...

      The string is getting inserted but the problem is it is getting stored in AlphaNumeric format...

      Can anyone help me in sorting out this...Why is this happening so????

      ThankYou,
      Malathi.
      That doesn't surprise me much: using updateString() stores a String value
      at that particular column in the database. What did you expect?

      kind regards,

      Jos

      Comment

      • malathi krishna
        New Member
        • Aug 2007
        • 8

        #4
        Originally posted by r035198x
        What do you mean by "it is getting stored in AlphaNumeric format..."?
        Can you give us an example of what is happening? Also post the code you're using for inserting the string.

        Hi,

        Below is the code which iam using... below which is the sample output...

        [CODE=java] import java.sql.*;

        class updatestring
        {
        public static void main(String args[])
        {
        String url="jdbc:odbc: database";
        String userID="scott";
        String password="tiger ";
        Connection con;
        Statement stmt;
        ResultSet rs;
        int rollno;
        int marks;
        String name;
        String printrow;

        try
        {
        Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
        con=DriverManag er.getConnectio n(url,userID,pa ssword);

        String query="SELECT rollno,name,mar ks FROM stud";
        stmt=con.create Statement(Resul tSet.TYPE_SCROL L_INSENSITIVE,R esultSet.CONCUR _UPDATABLE);
        rs=stmt.execute Query(query);

        boolean hasnext=rs.next ();
        if(!hasnext)
        {
        System.out.prin tln("No data returned");
        System.exit(3);
        }
        rs.updateInt(1, 3);
        rs.updateString (2,"lalit");
        rs.updateInt(3, 100);
        rs.insertRow();
        do
        {
        rollno = rs.getInt(1);
        name = rs.getString (2);
        marks = rs.getInt(3);
        printrow = rollno + " " + name + " " + marks;
        System.out.prin tln (printrow);
        } while (rs.next() );

        stmt.close();
        con.close();
        }
        catch(Exception ex)
        {
        System.err.prin tln("Exception caught "+ex);
        }


        }
        }
        [/CODE]



        ==========sampl e output========= ======

        3 6C616C6974 100




        this is the problem which i am facing.....let me know if any details required further...

        ThankYou,
        Malathi.
        Last edited by r035198x; Aug 9 '07, 07:13 AM. Reason: added the missing code tags

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          See the examples given in the docs on how to use the Scrollable resultset correctly.

          Comment

          • praveen2gupta
            New Member
            • May 2007
            • 200

            #6
            Originally posted by malathi krishna
            Hi,

            When iam working with JDBC, i tried to update the database table through updateStirng() method through java program...

            The string is getting inserted but the problem is it is getting stored in AlphaNumeric format...

            Can anyone help me in sorting out this...Why is this happening so????

            ThankYou,
            Malathi.
            Hi
            Your code is correct.there seems to be no problem. I think you have not inserted proper data in the table. Pls Insert 10 proper recods in the table and then show the output.

            Comment

            • malathi krishna
              New Member
              • Aug 2007
              • 8

              #7
              Originally posted by praveen2gupta
              Hi
              Your code is correct.there seems to be no problem. I think you have not inserted proper data in the table. Pls Insert 10 proper recods in the table and then show the output.

              Hi Praveen,
              This is my result in database after inserting records in the program...



              FIRSTNAME LASTNAME
              -------------------- -------------------
              6D6F68616E 6B756D6172
              6D6F68616E 6B756D6172
              6D6F68616E 6B756D6172
              6D6F68616E 6B756D6172
              6D6F68616E 6B756D6172
              6D6F68616E 6B756D6172
              6D6F68616E 6B756D6172
              6D6F68616E 6B756D6172
              6E656572616A 736861726D61
              6E656572616A 736861726D61
              6E656572616A 736861726D61

              Let me know if any data required.

              ThankYou,
              Malathi.

              Comment

              • praveen2gupta
                New Member
                • May 2007
                • 200

                #8
                Hi

                Insert Line
                Code:
                rs.moveToInsertRow();
                Before the following Line
                rs.updateInt(1, 3);
                rs.updateString (2,"lalit");
                rs.updateInt(3, 100);
                rs.insertRow();

                tell the results what happens.

                Comment

                • malathi krishna
                  New Member
                  • Aug 2007
                  • 8

                  #9
                  Originally posted by praveen2gupta
                  Hi

                  Insert Line
                  Code:
                  rs.moveToInsertRow();
                  Before the following Line
                  rs.updateInt(1, 3);
                  rs.updateString (2,"lalit");
                  rs.updateInt(3, 100);
                  rs.insertRow();

                  tell the results what happens.
                  Hi Praveen,

                  No changes even after adding that code. The result is in alpha numeric only...

                  ThankYou,
                  Malathi.

                  Comment

                  • praveen2gupta
                    New Member
                    • May 2007
                    • 200

                    #10
                    Hi
                    I will look this problem tomarrow, right now leaving office, show your table structure also for the above written code.

                    Comment

                    Working...