Link to home
Start Free TrialLog in
Avatar of rajcspalani
rajcspalani

asked on

oracle sysdate in preparedstatement

I am using preparedstatement to insert values into my table.Here is My table structure  AUDIT_TRIAL (number,number,timestamp,varchar2). I want to insert current date & time on 3rd column, so, i am using sysdate(stmt.setString(3,"sysdate")), but it is giving error that "ORA-01858: a non-numeric character was found where a numeric was expected". Please resolve this issue.
Advance thanks

public static void addAuditTrial(int adminId, String desc){
		Connection con = null;
		PreparedStatement stmt = null;
		String insertStatement = "insert into "+ADMIN_AUDIT_TRIAL+" values(?,?,?,?)";
		
		try {
			con = DBConnection.getDBConnection();
			int nextId = DBConnection.getNextID(ADMIN_AUDIT_TRIAL, "AT_ID",	con);
			stmt = con.prepareStatement(insertStatement);
			stmt.setInt(1, nextId);
			stmt.setInt(2, adminId);
			stmt.setString(3, "sysdate");
			stmt.setString(4, desc);
			stmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();		
		}
 
		finally {
			try {
				stmt.close();
				DBConnection.closeConnection(con);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}		
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of kadaba
kadaba
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rajcspalani
rajcspalani

ASKER

Thank you, it is working fine