Question: The code below give me syntax error, can you correct it and send me the correct one: import java.sql.*; public class Employees { // First

The code below give me syntax error, can you correct it and send me the correct one:

import java.sql.*;

public class Employees {

// First Creating the Database

static final String DB_URL = "jdbc:mysql://localhost/";

static final String USER = "enter your username";

static final String PASS = "enter your password";

PreparedStatement p = null;

ResultSet rs = null;

public static void main(String[] args) {

// Open a connection

try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);

Statement stmt = conn.createStatement();

) {

String sql = "CREATE DATABASE EMPLOYEES";

stmt.executeUpdate(sql);

System.out.println("Database created successfully...");

// Adding columns into the database

String sql2 = "CREATE TABLE Employees (Noemp int,startdate DATE, enddate DATE) ";

// Retrieving the data from the database

String sql = "select noofemployee,startdate,enddate from employees";

p = conn.prepareStatement(sql);

rs = p.executeQuery();

System.out.println("No. of employees \t\ Start Date \t\ End Date");

// Condiion check

while(rs.next()) {

int noemp = rs.getInt("Noemp");

String strtdate = rs.getString("startdate");

String enddate = rs.getString("enddate");

System.out.println(noemp + "\t\t" + strtdate + "\t\t" + enddate);

}

} catch (SQLException e) {

e.printStackTrace();

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!