Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Jdbc (http://www.go4expert.com/forums/jdbc-t27397/)

Rizwan Khan 18Dec2011 16:13

Jdbc
 
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

ewaldhorn 28Dec2011 14:12

Re: Jdbc
 
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/tutori.../prepared.html for more information regarding prepared statements.

Good luck with your code.


All times are GMT +5.5. The time now is 17:56.