Please send your Questions & Answers or Feedback to "mohan@javabook.org"

How do I create a database connection?

The database connection is created in 3 steps:
1. Find a proper database URL
2. Load the database driver
3. Ask the Java DriverManager class to open a connection to your database
In java code, the steps are realized in code as follows:
1. Create a properly formatted JDBR URL for your database. A JDBC URL has the form
jdbc:someSubProtocol://myDatabaseServer/theDatabaseName
2.
try {
Class.forName("my.database.driver");
} catch(Exception ex)
{
System.err.println("Could not load database driver: " + ex);
}
3. Connection conn = DriverManager.getConnection("a.JDBC.URL", "databaseLogin",
"databasePassword");
Related Posts Plugin for WordPress, Blogger...
Flag Counter