0

I have a MSSQL Database, and I have a stored procedure for any possible query, most of them just return a row of data with 3 columns or just execute an INSERT
How in java to connect to the DB and execute a stored procedure, and retrieve some data ?

3 Answers 3

4

A connection pool like DBCP makes a big difference. The connection time can be save this way.

Prepared statements can help the database to skip query parsing. The parsed statements will be cached.

Batch updates help when you're executing a statement repeatedly.

Setting the right fetch size is another optimization for queries.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm going to get just a row of data, always, this means I should set a fetch size of 1 ?
3
  1. Use the MSSQL JDBC Driver to create a connection to the database
  2. In jdbc, you need to create a CallableStatement to execute the procedure. It's like this:

.

CallableStatement callable = null;
try {
   String sqlCommand = "{call yourProcNameHere (?, ? /* ... */)}";
   callable = conn.prepareCall(sqlCommand);
   // ...
}
catch (SQLException e) {
   // ...
}
finally {
   / ...
}

1 Comment

The jTDS driver can be used to connect to MSSQL and Sybase. jtds.sourceforge.net
2

By reading and working through a JDBC Tutorial.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.