How To Access MySQL Database From Java Applications?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-access-mysql-database-from-java-applications/
PINTEREST
PINTEREST
INSTAGRAM

Java is popular programming language generally used commercial and enterprise applications. MySql is popular database too which is used big service providers like Google, Facebook etc. Most of the applications generally uses data and needs to store this data in a relational database. MySQL is generally the first choice if we do not want to give money for license. In this tutorial we will look how to connect a Java applications into MySQL database in detail.

Create Context and DataSource

Jdbc MySql driver can be used to connect MySql database like below. Jdbc driver is by default provided by Java Development Kit or simply JDK.

  • new InitialContext() creates a context for us.

Configure MySql Database Connection

  • We create MySql datasource
  • Then set MySql Server username and password to connect with setUser and setPassword .
  • We set MySql Server address or dns name with mysql.poftut.com

Connect and Query MySql Database

  • We create real connection object and assign to conn
  • We create query statement into stmt
  • rs result set is populated with query executed by stmt
  • rs, stmt, conn are closed with close function to release resources
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/how-to-access-mysql-database-from-java-applications/
PINTEREST
PINTEREST
INSTAGRAM

LEARN MORE  Java JDK vs JRE What Are Differences and Similarities?

Leave a Reply

Your email address will not be published.