cancel
Showing results for 
Search instead for 
Did you mean: 

writing data form Webdyn Pro inputfield into MySQL db

Former Member
0 Kudos

Hi, Im looking for an example project, tutorial or whatever which will tell me how to write string from an Inputfield into MySQL database under existing table/record. Regards

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

I got

"The specified thread [0] was not found.

Useful links:

Forum Home -- browse the forums here.

Search Forums -- visit the search page to query all forum content."

under those two links you gave me Bala. Ill try later.

That code above was very helpfull, thank you. Regards.

Former Member
0 Kudos

Hi,

Following code will help you to insert data to an existing table.


 Connection conn = null;
		try {
			//sapdbc.jar is the MySQL Driver it should be part ot the java/lib or ext
			Class.forName("com.sap.dbtech.jdbc.DriverSapDB");
			String urlConn = "jdbc:sapdb://localhost/maxdb1"; //replace localhost and the maxdb1 with your server name and database.
			String username = "userID";
			String password = "password";
			conn = DriverManager.getConnection(urlConn, username, password);
			System.out.println("connected to DB...");
			
			//Here the table name is table one which contains 1 field of data type string, change the following as per yours.
			PreparedStatement stmt = conn.prepareStatement("insert into table1 values(?)"); 
			
			//get the value entered in the inputfield which is mapped to an attribute called ID, change ths according to your req.
			String value = wdContext.currentContextElement().getID();
			conn.setAutoCommit(false);
			stmt.setString(1, value);
			stmt.execute();
			conn.commit();
		} catch (Exception e) {
			e.printStackTrace();
		} // catch

If you want to get the connection object from an already existing data source change the connection part of the above code as follows


try {
			InitialContext initialContext = new InitialContext();
//Change the alias name to that of yours.
			DataSource dataSource = (DataSource)initialContext.lookup("jdbc/Alias_Maxdb");
			connection= dataSource.getConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

Regards

Ayyapparaj

Former Member
0 Kudos