0% found this document useful (0 votes)
7 views

Advance Java Programming Code

Uploaded by

Harsha Vardhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Advance Java Programming Code

Uploaded by

Harsha Vardhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

Advance Java Programming Code

Topic 1- JDBC
Navigation path:
Step1: File new Java project create project name & finish
Step2: Right click on Project file New Class create class name &
finish.
Step3: Right click on Project file Build path Configure Build path
Library Add External Jars Download mysql-connector-j-8.3.0. (not
available means, just go to google & download MySQL connector j)
[Also must create database and table in MySQL Command line client]

1. Create Table program.

package com.s4;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class CreateTable1


{
public static void main(String a[])
{
String str1="jdbc:mysql://localhost:3306/AN12345";
String str2="root";
String str3="root";
try

Prepared by Prof. Tamilarasi R


{
Class.forName("com.mysql.cj.jdbc.Driver");
Connectioncon=DriverManager.getConnection(str1,str2,str3);
Statement st=con.createStatement();
st.executeUpdate("create table emp(empname varchar(20),empno
int,empaddr varchar(100))");
System.out.println("****Connected****");
con.close();
st.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();

}
}
}
2. Insert Table program.
package com.b1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class InsertT {
public static void main(String a[])

Prepared by Prof. Tamilarasi R


{
String str1="jdbc:mysql://localhost:3306/ AN12345";
String str2="root";
String str3="root";
Try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection(str1,str2,str3);
Statement st=con.createStatement();
st.executeUpdate("Insert into employee values('rajesh',146,'banglore')");
st.executeUpdate("Insert into employee values('chandra',149,'kadapa')");
st.executeUpdate("Insert into employee values('Nikhil',148,'vizag')");
System.out.println("*******INSERTED******");
con.close();
st.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();

Prepared by Prof. Tamilarasi R


}
}
}
3. Update Table program.
package com.b2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Update {


public static void main(String a[])
{
String str1="jdbc:mysql://localhost:3306/ AN12345";
String str2="root";
String str3="root";
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection(str1,str2,str3);
Statement st=con.createStatement();
st.executeUpdate("Update employee set id=142 where id=149");
System.out.println("*******UPDATED******");
con.close();

Prepared by Prof. Tamilarasi R


st.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
}

4. Delete Table program.

package com.b2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Display {


public static void main(String a[])
{
String str1="jdbc:mysql://localhost:3306/ AN12345";
String str2="root";

Prepared by Prof. Tamilarasi R


String str3="root";
Try
{

Class.forName("com.mysql.cj.jdbc.Driver");

Connection con=DriverManager.getConnection(str1,str2,str3);

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select * from employee");

while(rs.next())

String name1=rs.getString("empname");
String address1=rs.getString("empaddress");
int id1=rs.getInt("id");
System.out.println("empname is"+name1+",empid is
"+id1+",empaddress is"+address1);
}
System.out.println("*******Display******");
con.close();
st.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
catch(ClassNotFoundException e)
{

Prepared by Prof. Tamilarasi R


e.printStackTrace();
}
}
}

Topic 2- Swing and JDBC


Navigation path:

Step1: File new Java project create project name & finish
Step2: Right click on Project file New Other Select JFrame & Next
Give Package Name and Class Name & Finish.
Step3: Right click on Project file Build path Configure Build path
Library Add External Jars Download mysql-connector-j-8.3.0 and rt
jar file ( To get rt-jar, you have to go C-drive Program Files Java
jre1.8.0_341 lib and Select rt-jar )
[Note: Some program only need MySQL]

Prepared by Prof. Tamilarasi R


1. Eligible for Voting program

Design Part:

Source code:

Ok button:

final JLabel l3 = new JLabel(""); This code alone, I cut


l3.setBounds(75, 198, 277, 39); and pasted from down
to top. So, check
contentPane.add(l3); carefully and do it.

JButton btnOk = new JButton("OK");


btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String name=textField.getText();
int age=Integer.parseInt(textField1.getText());

Prepared by Prof. Tamilarasi R


if(age>=18)
l3.setText(name+" is eligible for voting");
else
l3.setText(name+" is not eligible for voting");
}
});

Resent button:

JButton btnReset = new JButton("RESET");


btnReset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
textField.setText("");
textField_1.setText("");
l3.setText("");
}
});

Prepared by Prof. Tamilarasi R


2. Username and Password program (you have create username
and password in Mysql)
Design part:

Source code:
Ok button:

final JLabel l3 = new JLabel(""); This code alone, I cut


and pasted from down
l3.setBounds(104, 220, 287, 30); to top. So, check
carefully and do it.
contentPane.add(l3);

JButton btnNewButton = new JButton("OK");


btnNewButton.addActionListener(new ActionListener()
10

Prepared by Prof. Tamilarasi R


{
public void actionPerformed(ActionEvent arg0)
{
String name=t1.getText();
String pwd=t2.getText();
String s1="jdbc:mysql://localhost:3306/test";
String s2="root";
String s3="root";
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection(s1,s2,s3);
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from users where
name='"+name+"' and pwd='"+pwd+"'");
if(rs.next())
l3.setText("***LOGIN SUCCESSFUL*******");
else
l3.setText("***LOGIN NOT SUCCESSFUL*******");
}
catch(SQLException e)
{
e.printStackTrace();

11

Prepared by Prof. Tamilarasi R


}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
});

12

Prepared by Prof. Tamilarasi R


Topic 3- Servlet
Navigation path
Step1: File new other Dynamic Web Project Next &give project
name.
Step2: Right click on Dynamic web Project file New Class type class
name & finish.
Step3: Right click on Dynamic web Project file New HTML file
index.html Finish.

How to install the server:


Step4: Window Show view Other Server.
Step5:

Have to click that line, which is shown in server,


Right click on Server link New Server Apache Tomcat v7.0
Server Finish click on Browser go to Download apache-
tomcat-7.0.47-windows-x64 folder select apache-tomcat-7.0.47

[You have to go google (type) download tomcat 7 click on Index of


/dist/tomcat/tomcat-7 click v7.0.47 (version) click bin/ file

13

Prepared by Prof. Tamilarasi R


Click apache-tomcat-7.0.47-windows-x64 folder (automatically
download)
Come back and select Src/ file apache-tomcat-7.0.47-src.zip . then
extract the file.

1.java program using the servlet concept of username and query


executing?
Index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>DemoServlet</title>
</head>
<body bgcolor=cyan>
<form method="get" action="ServletFirstDemo">
<pre>
Enter Your Name:<input type="text" name=t1>
<input type=submit><input type=reset>
</pre>
</form>
</body>
</html>

14

Prepared by Prof. Tamilarasi R


ServletDemo:
package com.s1;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/ServletFirstDemo")
public class ServletFirstDemo extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse
res) throws IOException,ServletException
{
PrintWriter pw=res.getWriter();
String s=req.getParameter("t1");
pw.println("<h1>Hello"+s);
pw.close();
}

15

Prepared by Prof. Tamilarasi R


2.Java program adding two numbers using servlets?
Index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor=Yellow>
<form action="AddingServlet">
Enter 1st Number:<input type="text" name="t1"><br><br>
Enter 2nd Number:<input type="text" name="t2"><br><br>
<input type="Submit" value="Add">
</form>
</body>
</html>
Servlet code:
package com.s2;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

16

Prepared by Prof. Tamilarasi R


import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/AddingServlet")
public class AddingServlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse
res)throws IOException, ServletException
{
int a=Integer.parseInt(req.getParameter("t1"));
int b=Integer.parseInt(req.getParameter("t2"));
int c=a+b;
PrintWriter pw=res.getWriter();
pw.println("<html><body bgcolor=aaff99><h1>");
pw.println("ADDING is ...."+c);
pw.println("</h1></body></html>");
}
}

17

Prepared by Prof. Tamilarasi R


3.login form using servlet:
Servlet code:
package com.s3;
import java.io.IOException;

import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse
res)throws IOException, ServletException
{
PrintWriter pw=res.getWriter();
String username=req.getParameter("t1");
String password=req.getParameter("t1");
if("telugu".equals(username)&& "123".equals(password))

18

Prepared by Prof. Tamilarasi R


{
pw.println("LogIn Sucess");
pw.close();
}
else
{
pw.println("LogIn Failed");
pw.close();
}
pw.close();
}
}
Index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body bgcolor=white>
<form action="LoginServlet"method="get">
<label for="username">user name:</label>
<input type="text" id="username" name="t1">

19

Prepared by Prof. Tamilarasi R


<label for="password">password:</label>
<input type="text" id="password" name="t2"><br><br>
<input type="Submit" value="Login">
</form>
</body>
</html>
4.java program on servlet to cookie (servlet to servlet):
Index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Servlet1cookie" method="post">
Name:<input type="text" name="userName"/><br/>
<input type="submit" value="go">
</form>
</body>
</html>

20

Prepared by Prof. Tamilarasi R


Servlet1cookie:
package com.k1;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/Servlet1cookie")
public class Servlet1cookie extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse
response)throws IOException,ServletException
{
try
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String n=request.getParameter("userName");

21

Prepared by Prof. Tamilarasi R


out.print("Welcome "+n);
Cookie ck=new Cookie("uname",n);//creating cookie object
response.addCookie(ck);
out.print("<form action='Servlet2Cookie' method='post'>");
out.print("<input type='submit' value='go'>"); out.print("</form>");
out.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

Servlet2cookie:
package com.k1;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

22

Prepared by Prof. Tamilarasi R


import javax.servlet.http.HttpServletResponse;

public class Servlet2cookie extends HttpServlet


{
public void doPost(HttpServletRequest request,
HttpServletResponse response)throws IOException,ServletException
{
try
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
Cookie ck[]=request.getCookies();
out.print("Hello "+ck[0].getValue());
out.close();
}
catch(Exception e)
{
System.out.println(e);
}
}

23

Prepared by Prof. Tamilarasi R


Topic 4- JSP
Navigation Path:

Step1: File new other Dynamic Web Project Next &type project
name.
Step2: Right click on Dynamic web Project file New JSP file give
index.jsp & finish.
Step3: Right click on Dynamic web Project file New HTML file
index.html Finish.

[Need for servlet file means follow step 4] [Server required]


Step4: Right click on Dynamic web Project file New Class give class
name & finish.

1. JSP Code:
<%@ page language="java" contentType="text/html; charset=ISO-
8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">
<title>Insert title here</title>

24

Prepared by Prof. Tamilarasi R


</head>
<body><h1>Welcome JSP</h1>
</body>
</html>

2. JSP + Html + Servlet Code:


Create a Login page for Student Registration Form
Login page.jave:
package com.s2;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/LoginPage")
public class LoginPage extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
String uname=request.getParameter("uname");

25

Prepared by Prof. Tamilarasi R


String password=request.getParameter("password");
if(uname.equals("tamil")&& password.equals("123"))
{
response.sendRedirect("success.jsp");
}
else
{
response.sendRedirect("error.jsp");
}
}
}

Student.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Student Registration Form</title>
</head>
<body>
<form action="hello.jsp" method="post">
First name: <input type="text" name="firstName" />
<br/><br/> Last name: <input type="text" name="lastName" />

26

Prepared by Prof. Tamilarasi R


<br/><br/>
<input type="submit" value="Submit" />

</form>

</body>
</html>

Login.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-
8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="LoginPage"><pre>
Enter user name:<input type="text" name="uname"><br>
Enter password:<input type="password" name="password"><br>
<input type=submit value=login> <input type=reset></pre>
</form>

27

Prepared by Prof. Tamilarasi R


</body>
</html>
hello.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-
8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">
<title> Student Confirmation Title</title></head>
<body>
<ul>
<li><p><b>First Name:</b>
<%= request.getParameter("firstName") %>
</p></li>
<li><p><b>Last Name:</b>
<%= request.getParameter("lastName") %>
</p></li>
</ul>
</body>
</html>

28

Prepared by Prof. Tamilarasi R


success.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-
8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">
<title>login success</title>
</head><h1> Login Successfully....</h1>
<body>
</body>
</html>
error.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-
8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">

29

Prepared by Prof. Tamilarasi R


<title>Unsuccessful login</title>
</head><h1> Unsuccessful login</h1>
<body>
</body>
</html>

3. JSP+JDBC+MySQL Code
Index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="index.jsp" method="post">
User name: <input type="text" name="usr"/>
password: <input type="password" name="pwd"/>
<input type="submit"/>
</form>
</body>
</html>
Reg1.html:

30

Prepared by Prof. Tamilarasi R


<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="regl.jsp" method="post">
User name: <input type="text" name="usr"/>
password: <input type="password" name="pwd"/>
<input type="submit"/>
</form>
</body>
</html>
Index.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-
8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">

31

Prepared by Prof. Tamilarasi R


<title>Insert title here</title>
</head>
<body>
<%@ page import="java.sql.*"%>
<%
String user_id=request.getParameter("usr");
session.putValue("user_id",user_id);
String pwd=request.getParameter("pwd");
Class.forName("com.mysql.cj.jdbc.Driver");
java.sql.Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/kou
stubh","root","root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from login where
user_id='"+user_id+"'");
if(rs.next())
{
if(rs.getString(2).equals(pwd))
{
out.println("welcome..... "+user_id);
}
else
{
out.println("Invalid password try again");

32

Prepared by Prof. Tamilarasi R


}
}
else
%>
</body>
</html>
Reg1.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-
8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">
<title>Insert title here</title>
</head>
<body>
<%@ page import="java.sql.*" %>
<%
String usr=request.getParameter("usr");
session.putValue("user_id",usr);
String pwd=request.getParameter("pwd");

33

Prepared by Prof. Tamilarasi R


Class.forName("com.mysql.cj.jdbc.Driver");
java.sql.Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/kou
stubh","root","root");
Statement st=con.createStatement();
ResultSet rs;
int i=st.executeUpdate("insert into login
values('"+usr+"','"+pwd+"')");
out.println("Registered...");
%>
</body>
</html>

Topic 5- Hibernate
Navigation path:
Step1: File new other Maven Project next org.mavan
apache.archetype quickstart 1.1 or 1.4 ( quickstart not is mavan project
means [go to google (type) mavan archetype quickstart 1.1 copy
group id, artifact id, version, URL ]

Step2: Right click on maven project folder New Class [including


package name]

34

Prepared by Prof. Tamilarasi R


For hibernate file we have to install JBoss tool
Step3: Help Eclipse marketplace (type) hibernate and search
JBoss tool (with version) click install

Step4: Right click on project folder new other (type)


hibernate select Hibernate. Configure .cfg.xml finish one
window will open, in that you have fill MySQL URL, local host address,
database, username & password click ok.

How to get maven dependency


Hibernate dependency:
Step5: Open Google search (type) Maven dependency click Maven
Repository: Search/Browse/Explore (In search, have to type) hibernate
Hibernate Core Relocation select version 8.0.33 copy dependency
paste to pom.xml

MySQL connector dependency:


(In search, have to type) Mysql connector j MySQL Connector Java
select version 6.3.1 copy dependency paste to pom.xml

(In MySQL have to create database alone and check whether


your table is created automatically or not)
1. To create tables, update, modify, and delete using Hibernate
concept.
App.java:
package com.s1.DemoMaven;

import org.hibernate.Session;

35

Prepared by Prof. Tamilarasi R


import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
Configuration cf=new Configuration();
cf.configure().addAnnotatedClass(RegisterStu.class);
SessionFactory sf=cf.buildSessionFactory();
Session ss=sf.openSession();
Transaction tr=ss.getTransaction();
tr.begin();

RegisterStu s1=new RegisterStu();


s1.setRno(888);
s1.setName("sathish");
ss.save(s1);

36

Prepared by Prof. Tamilarasi R


/*RegisterStu s2=ss.get(RegisterStu.class,888);
s2.setName("sumit");
ss.update(s2);*/

/*RegisterStu s3=ss.get(RegisterStu.class,333);
System.out.println("the deleted record" + s3.getName());
ss.delete(s3);*/

tr.commit();
}
}
RegisterStu.java:
package com.s1.DemoMaven;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;

@Entity
public class RegisterStu {
@Id
private int Rno;
private String Name;

37

Prepared by Prof. Tamilarasi R


public int getRno() {
return Rno;
}
public void setRno(int rno) {
Rno = rno;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
}

Hibernate.cfg.xml:
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/tami</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="hibernate.show_sql">true</property>
</session-factory>
</hibernate-configuration>

38

Prepared by Prof. Tamilarasi R


DemoMaven/pom.xml
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-
java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-
core -->

39

Prepared by Prof. Tamilarasi R


40

Prepared by Prof. Tamilarasi R

You might also like