You are on page 1of 7

Database Connection

with Java
SOFTWARE ENGINEERING
Requirements

 Java Complier (Eclipse)


 Database Management System (MySQL)
 SQL Connector Jar File
Connection.Jar

 Download File
 https://www.javatpoint.com/src/jdbc/mysql-connector.jar
 Go to C/ProgramFiles/Java/JRE/Lib/Ext
 Paste SQL Connector File.
Create Database

 Create Database with a meaningful name


 Create Table Login
 Create 3 attributes (id , name, password)
Create Project and Connect DB
 Create Java Project and Add a Jframe with Absolute Layout
 Make an interface for login
 Go to event handler of Login Button
 Write Class.forname(“com.mysql.jdbc.Driver”)
 Create a Connection Object
 Connection Con = DriverManager.getConnection(Host,UserName,Password)
 Create a Statement Object
 Statement St = Con.createStatement();
 Write a Query “Select *From Table where………”
Cont…
 Create a ResultSet Object
 ResultSet RS = ST.executeQuery(Query)
 If(RS.next){
 Code…..
 }
Inserting Record
 Same as Previous Create Connection
 Get the Values from TextBoxes and Store in String Variables
 Write a Query “Inser INTO Table(Attributes) Values(?,?)
 Create a PreparedStatement Object
 PreparedStatement PR = Con.prepareStatement(Query);
 Set the Strings or Int of PR
 PR.setString(index,value) , PRsetInt(index,value)
 PR.execute()

You might also like