What are the different types of Statements?

1.Statement (use createStatement method) 2. Prepared Statement (Use prepareStatement method) and 3. Callable Statement (Use prepareCall)

Showing Answers 1 - 1 of 1 Answers

Sreekanth

  • Jun 2nd, 2005
 

try 

 
Connection conn = DriverManager.getConnection("URL",'USER"."PWD"); 
 
//For Simple statement used for static query. 
Statement stmt = conn.createStatement();  
 
//For a runtime / dynamic query .Where String is a dynamic query you want to execute 
 
PreparedStatement pstmt = conn.prepareStatement(String sql); 
 
 
//For Stored procedure Callable statement, where sql is stored procedure. 
 
CallableStatement cstmt = conn.prepareCall(String sql); 

catch (SQLException ee) 

ee.printStackTrace(); 

 
Don't forget all the above statements will throw the SQLException, so we need to use try catch for the same to handle the exception.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions