Static final String DB_URL = "jdbc:mysql://localhost/TUTORIALSPOINT" This sample code has been written based on the environment and database setup done in the previous chapter.Ĭopy and paste the following example in TestApplication.java, compile and run as follows − This sample example can serve as a template when you need to create your own JDBC application in the future. Open a connection: Requires using the DriverManager.getConnection() method to create a Connection object, which represents a physical connection with the database.Įxecute a query: Requires using an object of type Statement for building and submitting an SQL statement to the database.Įxtract data from result set − Requires that you use the appropriate ResultSet.getXXX() method to retrieve the data from the result set.Ĭlean up the environment − Requires explicitly closing all database resources versus relying on the JVM's garbage collection. Most often, using import java.sql.* will suffice. Import the packages: Requires that you include the packages containing the JDBC classes needed for database programming. There are following six steps involved in building a JDBC application − This will show you how to open a database connection, execute a SQL query, and display the results.Īll the steps mentioned in this template example, would be explained in subsequent chapters of this tutorial. This chapter provides an example of how to create a simple java based application to access MySQL database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |