Skip to main content

Posts

Showing posts from July, 2021

Python Evaluation Hackerrank Solution | Hackerrank Python

 Python Evaluation Hackerrank Solution For Explanation Watch Video : Code:: # Enter your code here. Read input from STDIN. Print output to STDOUT eval(input())

Draw The Triangle 2 Hackerrank Solution - SQL

 Draw The Triangle 2 Hackerrank Solution - SQL  for explanation watch video: Code:: set serveroutput on; declare res clob; begin  for i in 1..20 loop      res := '';      for j in 1..i loop        res := res || '*' || ' ';      end loop;      dbms_output.put_line(res);  end loop; end; /

Draw The Triangle 1 Hackerrank Solution - SQL

  Draw The Triangle 1 Hackerrank Solution - SQL for Explanation watch Video : Code:: set serveroutput on; declare res clob; begin for i in reverse 1..20 loop res := ''; for j in 1..i loop res := res || '*' || ' '; end loop; dbms_output.put_line(res); end loop; end; /

Print Prime Numbers Hackerrank Solution - PL/SQL

 Print Prime Numbers Hackerrank Solution - PL/SQL for explanation watch video ::  Code:: set serveroutput on; declare output clob := ''; co number; begin  for i in 2..1000 loop      co := 0;      for j in 2..(i/2) loop        if mod(i,j)=0          then            co := 1;            exit;         end if;     end loop;     if co = 0      then        output :=  output || i ||'&';     end if;     end loop;     dbms_output.put_line(substr(output,1,length(output)-1)); end; /

ResultSetMetaData in java

 ResultSetMetaData in java code:; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; class Test{ public static void main(String arg[]){ try(Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","tiger"); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select * from stu");){ //create ResultSetMetaData obj ResultSetMetaData rsmd = rs.getMetaData(); //get column count int colCount = rsmd.getColumnCount();//3 //print column name for(int i=1;i<=colCount;i++) { System.out.print(rsmd.getColumnName(i)+" "); } System.out.println(); //for column type for(int i=1;i<=colCount;i++) { System.out.print(rsmd.getColumnTypeName(i)+" "); } System.out.println(); }catch(SQL

JDBC Project - Log in Project With Mysql In Eclipse

JDBC Project - Log in Project With Mysql In Eclipse For explanation Watch Video :    Step 1: Create table 'login' in mysql step 2::  Insert Records Into 'login' table Step 3: Go to Eclipse and download swing related components Install Swing On Eclipse click on help at top of eclipse IDE after that click on install new software after that paste link in work with : 2020-12 - http://download.eclipse.org/releases/2020-12 i am using 2020-12 eclipse version at place of 2020-12 you can use your version name ex:: if your version of eclipse is oxygen then link : oxygen - http://download.eclipse.org/releases/oxygen expand click on general purpose tools and check the all tool from swing designer to end and after that click on  finish. After downloading all tools restart eclipse IDE. Download MySQL Jar File From here:  https://mvnrepository.com/artifact/mysql/mysql-connector-java/8.0.25 for connection method:: Connection con = null; PreparedStatement ps = null; public void con

Population Density Difference Hackerrank Solution - SQL

 Population Density Difference Hackerrank Solution - SQL For Explanation Watch Video : Code::  select max(population) - min(population) from city;

Japan Population Hackerrank Solution - SQL

 Japan Population Hackerrank Solution - SQL For Explanation Watch Video :  Code:: select sum(population) from city where countrycode = 'JPN';

JDBC - execute method in jdbc for select and non-select queries

  JDBC - execute method in jdbc for select and non-select queries For Explanation Watch Video :: Creation of table:: SQL> create table test2(eid int,ename varchar2(10)); Table created. SQL> insert into test2 values(1,'vijay'); 1 row created. SQL> insert into test2 values(2,'rajesh'); 1 row created. SQL> select * from test2; EID ENAME ---------- ---------- 1 vijay 2 rajesh SQL> commit; Commit complete. JDBC code:: package com.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import java.util.Scanner; class Test { public static void main(String arg[])throws Exception{ //generate the connection Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","tiger"); //create statement Object Statement st = con.createStatement(); //get query from user Scanner

The PADS Hackerrank Solution - SQL

  The PADS Hackerrank Solution - SQL For Explanation Watch Video :  Oracle::  SELECT  NAME || '(' || SUBSTR(OCCUPATION,1,1) || ')' AS N FROM OCCUPATIONS ORDER BY N; SELECT 'There are a total of ' || COUNT(OCCUPATION) || ' ' || LOWER(OCCUPATION) || 's.' FROM OCCUPATIONS GROUP BY OCCUPATION ORDER BY COUNT(OCCUPATION), OCCUPATION; MySql: ======= SELECT CONCAT(NAME,'(',SUBSTR(OCCUPATION,1,1),')') AS NA FROM OCCUPATIONS ORDER BY NA; SELECT CONCAT('There are a total of ',COUNT(OCCUPATION),' ',LOWER(OCCUPATION),'s.') FROM OCCUPATIONS GROUP BY OCCUPATION ORDER BY COUNT(OCCUPATION), OCCUPATION;

SQL Query to find total employees department wise

 SQL Query to find total employees department wise For Explanation Watch Video:  SQL> select * from emp;      EMPNO ENAME      JOB               SAL     DEPTNO ----------      ----------      ----------      ----------           ----------       7788 scott             analyst          3630              10       7839 king             president        6050              10       7902 ford             analyst               3630            10       7903 miller           president        7000              20       7904 smith           professor        8000             20       7905 raja             clerk                 3630              30       7906 rajesh           salesman         8000             30       7907 raju             president             11000          30       7908 allu             clerk                 6050              20       7909 kyli             creater               5000             10       7910 james         clerk                 6000             20       1122 sa

JDBC Program For Age Calculator

JDBC Program For Age Calculator For Explanation Watch video :: Code :  import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Scanner; class Test   {  private static final String query = " select (sysdate-dob)/365.25 from emp88 where eid = ?";     public static void main(String arg[]){     try(Scanner scn = new Scanner(System.in)){     //take eid from user     System.out.println("Enter Emp id : ");     int eid = scn.nextInt();     try(Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","tiger");     PreparedStatement ps = con.prepareStatement(query);){     //set the eid     ps.setInt(1, eid);     //ResultSet Object     ResultSet rs = ps.executeQuery();     rs.next();     //get the age     float age = rs.getFloat(1);     System.out.pr

Apple and Orange Hackerrank Solution - Java

 Apple and Orange Hackerrank Solution - Java For Explanation Watch Video: Code:: import  java.io.*; import  java.math.*; import  java.security.*; import  java.text.*; import  java.util.*; import  java.util.concurrent.*; import  java.util.function.*; import  java.util.regex.*; import  java.util.stream.*; import   static  java.util.stream.Collectors.joining; import   static  java.util.stream.Collectors.toList; class  Result {      /*      * Complete the 'countApplesAndOranges' function below.      *      * The function accepts following parameters:      *  1. INTEGER s      *  2. INTEGER t      *  3. INTEGER a      *  4. INTEGER b      *  5. INTEGER_ARRAY apples      *  6. INTEGER_ARRAY oranges      */      public   static   void  countApplesAndOranges( int  s,  int  t,  int  a,  int  b, List<Integer> apples, List<Integer> oranges) {          int  count =  0 ;          for ( int  i= 0 ;i<apples.size();i++){              if (apples.get(i)+a>=s && apples.g

JDBC - Insert records into table using PreparedStatement

 JDBC - Insert records into table using PreparedStatement For Explanation watch Video : Code:: import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Scanner; public class Test { private static final String query = "insert into test1 values(?,?)"; public static void main(String[] args)throws Exception{ //generate connection try(Scanner scn = new Scanner(System.in)){ System.out.println("Enter The eid: "); int eid = scn.nextInt(); System.out.println("Enter employee name: "); String ename = scn.next(); try(Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","tiger"); PreparedStatement ps = con.prepareStatement(query);){ ps.setInt(1, eid); ps.setString(2, ename); int count = ps.executeUpdate(); if(count==0) { System.o

How to get the row count in JDBC?

How to get the row count in JDBC? For Explanation Watch Video:  Code:: package com.test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Scanner; public class Test { public static void main(String[] args)throws Exception{ //generate connection Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","tiger"); //sql Query String query = "select count(*) from stu"; //prparedStatement Object PreparedStatement ps = con.prepareStatement(query); //resultSet obj ResultSet rs = ps.executeQuery(); rs.next(); //fetch the data int count = rs.getInt(1); System.out.println("The No. Of Records : "+count); //close the connection con.close(); } }