How to make connection using jdbc,mysql,java source code
import java.sql.*;
import java.util.*;
public class FirstActivity
{
public static void main (String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.println ("Enter the Name");
String name=scan.nextLine();
System.out.println ("Enter the Salary");
double salary=scan.nextDouble();
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection cn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/university?autoReconnect=true&useSSL=false","root","root");
if(!cn.isClosed())
{
System.out.println ("database server connected");
PreparedStatement ps=cn.prepareStatement("insert into employee(name,salary)values(?,?)");
ps.setString(1,name);
ps.setDouble(2,salary);
int a=ps.executeUpdate();
if(a>0)
{
System.out.println ("record inserted");
}
}
cn.close();
}
catch(Exception e)
{
System.out.println ("Error is :"+e.getMessage());
}
}
}
Additional Reading
- SEO Practices Everyone Should Follow SEO Rules
- Complete Top SEO Checklist
- Yoast Seo Premium 15.2 Nulled – WordPress SEO Plugin
- Top 50+ SEO Interview Questions
- What is a Backlink? How to Get More Backlinks
- TCS INTERVIEW QUESTIONS – CLICKE HERE
- Top 20 Interview Program Questions
- Android Projects with Source Code
- Python Project With Source Code
- Python Projects Ideas
- Machine Learning MCQ Questions
- Highest Paying Earning Website
- School Database Management System
- Top 20 Company Interview Questions
0 Comments