on 03-10-2008 12:31 AM
Hi, I need an advice on code below. I made an db named "DBname" and inside table named "Date1". However I still fail to write anything from inputfield.
public void onActionSave(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionSave(ServerEvent)
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql://adress/DBname";
Connection con=DriverManager.getConnection(url,"user","password");
System.out.println ("Database connection established");
Date Date = wdContext.currentContextElement().getDate(); //Date = name of Context binded to Date IF
String sql = "insert into Date1 values (?)";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setDate(1, Date);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
After pressing "Save" button application starts "working" (the round coursor is moving) for around ~20seconds.
Please advice couse I have run out of ideas. Regards, Balmer
Hi,
Well i feel the execute statement is missing here.
stmt.executeUpdate();
thanks & regards,
Manoj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try this:
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql://adress/DBname";
Connection con=DriverManager.getConnection(url,"user","password");
System.out.println ("Database connection established");
Date Date = wdContext.currentContextElement().getDate(); //Date = name of Context binded to Date IF
String sql = "insert into Date1 values (?)";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setDate(1, Date);
stmt.executeUpdate();
stmt.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
If this doesn't work try debugging and check if the connection is fine.
Regards,
Satyajit.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The code seems to be fine. did u try checking the exception, if it is getting caught?
try including the column name also in the query, even there is only one column in the table. I know it sounds a bit strange, but long back even i was facing a similar issue. so had to change the query a bit. just give it a try and let me know if it is working
insert into <table name> (<col1>, <col2>) values (?,?)
Regards,
Gita
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, thank you for your help, I appreciate it. I did as you told but it didn't change anything. No errors are listed, no data written in the db. I fail to understand what is wrong here, problem is it has to work today... Got any other idea? Even slightest would be most welcome. Regards, Balmer.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.