1

Hey I'm trying to connect to a DB2 database, by using Servlets(Using NetBeans right now) but I just can't find a useful example on the web, could someone help me?

Thank you so much for your time.

1 Answer 1

3

It's no different to connecting to a DB2 database without using a Servlet :)

A quick Google search came up with some documentation on using JDBC with DB2. That page has some code examples that should get you started.

Essentially it's a matter of obtaining a Connection object using either the DriverManager or DataSource interfaces. Once you have that you can obtain Statements or PreparedStatements are you're good to go.

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

3 Comments

You'll want to consider using a connection pool rather than DriverManager if it's servlets.
@Duffymo makes a good point: if you're building a real-world system then you'll need a good connection pooling library, otherwise your system will have pretty bad latency. It's probably better to use a DataSource rather than DriverManager. DataSource is a better design and makes it much easier to transparently include things like connection pooling.
Everything else that Cameron said is spot on.

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.