cancel
Showing results for 
Search instead for 
Did you mean: 

How can I save a value of a editview in SQL database

Former Member
0 Kudos

Hi all,

I have build a webdynpro with a editview. I want to save the date in to a SQL table. The column in the table has the data type Long. Can someone give me a sample how to convert the text of the editview in to a Long data type.

Kind regards,

Richard

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Sebastian,

The JDBC connection is running correctly. My application is saving the rest of the values correctly in the table of the database. It is more that I can not save data from a textEdit to a field in the table. In the Webdynpro I have to use a String and I the database need to use a Float data type because of the more than thousend character.

This is the first time that I have to save multiple lines into a table field.

Kind Regards,

Richard

Former Member
0 Kudos

Richard,

but in the case your db does not accept the value there must be a SQLException or something like that. Also make sure that the db can convert the value to float:


// remove all n
s = s.replaceAll("\n", "");
// remove all whitespaces
s = s.replaceAll(" ", "");

If that not solves your issue, please post the value of your String and your insert statement.

Sebastian

Former Member
0 Kudos

sorry for my multiple post. I got an stactrace from the collaboration system everytime i clicked on post message.

Former Member
0 Kudos

Richard,

but in the case your db does not accept the value there must be a SQLException or something like that. Also make sure that the db can convert the value to float:


// remove all n
s = s.replaceAll("\n", "");
// remove all whitespaces
s = s.replaceAll(" ", "");

If that not solves your issue, please post the value of your String and your insert statement.

Sebastian

Former Member
0 Kudos

Richard,

but in the case your db does not accept the value there must be a SQLException or something like that. Also make sure that the db can convert the value to float:


// remove all n
s = s.replaceAll("\n", "");
// remove all whitespaces
s = s.replaceAll(" ", "");

If that not solves your issue, please post the value of your String and your insert statement.

Sebastian

Former Member
0 Kudos

Richard,

but in the case your db does not accept the value there must be a SQLException or something like that. Also make sure that the db can convert the value to float:


// remove all n
s = s.replaceAll("\n", "");
// remove all whitespaces
s = s.replaceAll(" ", "");

If that not solves your issue, please post the value of your String and your insert statement.

Sebastian

Former Member
0 Kudos

Richard,

but in the case your db does not accept the value there must be a SQLException or something like that. Also make sure that the db can convert the value to float:


// remove all n
s = s.replaceAll("\n", "");
// remove all whitespaces
s = s.replaceAll(" ", "");

If that not solves your issue, please post the value of your String and your insert statement.

Sebastian

Former Member
0 Kudos

Richard,

but in the case your db does not accept the value there must be a SQLException or something like that. Also make sure that the db can convert the value to float:


// remove all n
s = s.replaceAll("\n", "");
// remove all whitespaces
s = s.replaceAll(" ", "");

If that not solves your issue, please post the value of your String and your insert statement.

Sebastian

Former Member
0 Kudos

The dbms sould convert the string automatically to the type of your table field. But make sure that your string does not contain whitespaces or line breaks.

You can use:


s = s.replaceAll("\n", "");
s = s.replaceAll(" ", "");

If that does not solve your issue, please post the value of the string and your insert statement.

Former Member
0 Kudos

The dbms sould convert the string automatically to the type of your table field. But make sure that your string does not contain whitespaces or line breaks.

You can use:


s = s.replaceAll("\n", "");
s = s.replaceAll(" ", "");

If that does not solve your issue, please post the value of the string and your insert statement.

Former Member
0 Kudos

Hi all,

I tried to implement your source in to my webdynpro. I don't get any error, but data is not saved in the database field.

What could be the error.

Kind regards,

Richard

Former Member
0 Kudos

Hi Richard,

do you get any exceptions (make sure that in every try-catch-block the errors are reported to the MessageManager)? It might be that you have set the wrong lookup name for your database.

regards

Sebastian

Message was edited by: Sebastian Voss

Former Member
0 Kudos

sorry for my multiple post. I got an stacktrace from the collaboration system everytime i clicked on post message.

Message was edited by: Sebastian Voss

Former Member
0 Kudos

Hi Richard,

I dont know if u has problem with getting long values from TextEdit element or with sendingt that to database.

Sample to long values getting:


String text=wdContext.currentContextElement().getText();
//  split string from TextEdit
String[] res = text.split("n");
for (int i = 0; i < res.length; i++) {
   //convert strings to long
   res<i>=res<i>.trim();
   try{
	long l=Long.parseLong(res<i>);
   }catch (Exception e){//report or ignore exceptions}
}

</i>

Db sample is in last post.

I think u should better use PreparedQuery and set values wits setLong methods.

regards

Bogdan

Former Member
0 Kudos

Hi Dharmi,

Sorry I mean a TextEdit. I have save the text in to a sql table. the colomn in the table is a of datatype Long.

Kind Regards,

Richard

Former Member
0 Kudos

Hi Richard,

Have you deployed the JDBC driver on your J2EE server?

In case you haven't, then that's your starting point.

Check thread for the steps.

If you have the jdbc drivers installed, then use the following piece of code to save your TextEdit data:


InitialContext ctx = new InitialContext();
DataSource src = (DataSource) ctx.lookup("jdbc/MSSQL");
Connection sqlCon = src.getConnection();

if(sqlCon != null){
Statement stmnt = sqlCon.createStatement();
stmnt.executeUpdate("INSERT INTO <your table name> (<colName1, colName2...>) VALUES( '" + <your string variable> + "',...)");
}

Regards,

Satyajit.

Former Member
0 Kudos

Hello Richard,

What is editwiew? Do you mean the UI element Textview or TextEdit or something else? Can you please clarify?

Best regards,

Dharmi