on 02-09-2008 11:14 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
https://forums.sdn.sap.com/click.jspa?searchID=8718267&messageID=4723431
https://forums.sdn.sap.com/click.jspa?searchID=8718267&messageID=4830340
xxxxxxxxxxxxxxxxxxxxx
Edited by: Armin Reichert on Feb 18, 2008 7:31 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.