Jdbc

Discussion in 'Java' started by Rizwan Khan, Dec 18, 2011.

  1. Rizwan Khan

    Rizwan Khan New Member

    Joined:
    Dec 18, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I want to ask how to send string object or text in the insert query.
    or string or text from textfield to database............
    reply with small example
     
  2. ewaldhorn

    ewaldhorn New Member

    Joined:
    Feb 16, 2010
    Messages:
    36
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    Cape Town, South Africa
    Home Page:
    http://www.javak.co.za
    I think you'd be best served using a PREPARED STATEMENT.

    For example...

    Code:
    // con is the active Database Connection
    // All of this is in a try-catch block
    String mySqlString = "update THETABLE set TEXTMESSAGE = ? where MESSAGEID = ?";
    PreparedStatement myStatement = con.prepareStatement(mySqlString);
    
    myStatement.setString(1, theVeryLongTextMessage);
    myStatement.setInt(2, messageID);
    
    myStatement.executeUpdate();
    You could refer to http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html for more information regarding prepared statements.

    Good luck with your code.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice