Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I have tried the solutions on stackoverflow but it didnt solve my problem so i would like to ask it
- import java.*;
- import java.lang.*;
- import java.sql.*;
- import java.io.*;
- import java.util.*;
- public class mysql1
- {
- static final String url = "jdbc:mysql://localhost:3306/test";
- static final String usr = "root";
- static final String passwd = "";
- public static void main(String [] ar)
- {
- Connection con = null;
- // boolean flag = True;
- int ch;
- String y;
- try
- {
- System.out.println("connecting to db...n");
- con = DriverManager.getConnection(url,usr,passwd);
- System.out.println("Database Connected.n");
- CallableStatement cs = null;
- Statement stmnt = con.createStatement();
- do
- {
- Scanner in = new Scanner(System.in);
- System.out.println("1.Create Tablen");
- System.out.println("2.Insert Tablen");
- System.out.println("3.Display Tablen");
- System.out.println("4.Update Tablen");
- System.out.println("5.Delete Tablen");
- System.out.println("6.Creating indexn");
- System.out.println("7.Show indexn");
- System.out.println("8.Create Viewn");
- System.out.println("9.Show viewn");
- System.out.println("10. Inner Joinn");
- System.out.println("11. Right outer joinn");
- System.out.println("12. Left outer joinn");
- System.out.println("13. Cross joinn");
- System.out.println("14. Exitn");
- System.out.println("Enter your choice");
- ch = in.nextInt();
- switch(ch)
- {
- case 1:
- System.out.println("Creating table 1.n");
- String t1 = "create table employe(id int(10),"+"fname varchar(20),"+"lname varchar(15))";
- stmnt.executeUpdate(t1);
- System.out.println("Table 1 Created..n");
- System.out.println("Creating table 2.n");
- String t2 = "create table salary(id int(10),"+"fname varchar(20),"+"salray int(10))";
- stmnt.executeUpdate(t2);
- System.out.println("Table 2 Created..n");
- break;
- case 2:
- System.out.println("Entering data in 1st tablen");
- do
- {
- System.out.println("Enter id:n");
- int id = in.nextInt();
- String str = in.nextLine();
- System.out.println("Enter respective fname:n");
- String f = in.nextLine();
- System.out.println("Enter lname:n");
- String l = in.nextLine();
- PreparedStatement pstmnt = con.preparedStatement("insert into employe values(?,?,?)");
- pstmnt = setInt(1,id);
- pstmnt = setString(2,f);
- pstmnt = setString(3,f);
- pstmnt.executeUpdate();
- System.out.println("Do you want to continue? y/n");
- String ans = in.nextLine();
- }while(ans=='y');
- System.out.println("Entering data in 2nd tablen");
- do
- {
- System.out.println("Enter id:n");
- int id1 = in.nextInt();
- String str1 = in.nextLine();
- System.out.println("Enter respective fname:n");
- String f1 = in.nextLine();
- System.out.println("Enter the salaryn");
- int sal = in.nextInt();
- PreparedStatement pstmnt = con.preparedStatement("insert into salary values(?,?,?)");
- pstmnt = setInt(1,id);
- pstmnt = setString(2,f);
- pstmnt = setInt(3,f);
- pstmnt.executeUpdate();
- System.out.println("Do you want to continue? y/n");
- String ans = in.nextLine();
- }while(ans=='y');
- break;
- case 3:
- System.out.println("Displaying Table 1.....n");
- String display = "select * from employe";
- ResultSet rs1 = stmnt.executeQuery(display);
- System.out.println("ID t FNAME t LNAME");
- while(rs1.next())
- {
- System.out.println(rs1.getInt(1)+"t"+rs1.getString(2)+"t"+rs1.getString(3));
- }
- System.out.println("Displaying Table 2.....n");
- String display1 = "select * from salary";
- ResultSet rs4 = stmnt.executeQuery(display);
- System.out.println("ID t FNAME t SALARY");
- while(rs4.next())
- {
- System.out.println(rs4.getInt(1)+"t"+rs4.getString(2)+"t"+rs4.getInt(3));
- }
- break;
- case 4:
- String updat = "update employe set fname=?, lname=? where id=?";
- System.out.println("Enter the id of the employe that you want to update:n");
- int id1 = in.nextInt();
- System.out.println("Enter new fname:n");
- String f1 = in.nextLine();
- System.out.println("Enter new lname:n");
- String l1 = in.nextLine();
- PreparedStatement ps = con.preparedStatement(updat);
- ps.setString(1,f1);
- ps.setString(2,l1);
- ps.setInt(3,id1);
- ps.executeUpdate();
- break;
- case 5:
- System.out.println("Delete enteries from table using id......n");
- String del = "delete from employe where id=?";
- System.out.println("Enter the ID:n");
- int id2 = in.nextInt();
- PreparedStatement ps1 = con.PreparedStatement(del);
- ps1.setInt(1,id2);
- ps.executeUpdate();
- break;
- case 6:
- System.out.println("Creating Index.....n");
- String ind = "create index inde on employe(fname)";
- stmnt.executeUpdate(ind);
- System.out.println("Index created .....n");
- break;
- case 7:
- System.out.println("Display index.....n");
- String inde = "show index from employe";
- ResultSet rs2 = stmnt.executeQuery(inde);
- System.out.println(rs2.getString(1)+"t"+rs2.getString(2)+"t"+rs2.getString(3)+"t"+rs2.getString(4)+"t"+rs2.getString(5)+"t"+rs2.getString(6)+"t"+rs2.getString(7)+"t"+rs2.getString(8)+"t"+rs2.getString(9)+"t"+rs2.getString(10)+"t"+rs2.getString(11)+"t"+rs2.getString(12)+"tn");
- break;
- case 8:
- System.out.println("Create view......n");
- String vew = "create view v1 as select id,lname from employe";
- stmnt.executeUpdate(vew);
- System.out.println("View createdn");
- break;
- case 9:
- System.out.println("Displaying View......n");
- String disv = "select * from v1";
- ResultSet rs3 = stmnt.executeQuery(disv);
- while(rs3.next())
- {
- System.out.println(rs3.getInt(1)+"t"+rs3.getString(2));
- }
- break;
- case 10:
- String inner = "select * from employe e inner join salary sa on e.id=sa.id";
- ResultSet rs5 = stmnt.executeQuery(inner);
- System.out.println("IDtFNMEtlnamen");
- while(rs5.next())
- {
- System.out.println(rs5.getInt(1)+"t"+rs5.getString(2)+"t"+rs5.getString(3)+"n");
- }
- inner1 = "select * from salary sal employe e on sal.id=e.id";
- rs5 = stmnt.executeQuery(inner1);
- System.out.println("IDtFNMEtSalaryn");
- while(rs5.next())
- {
- System.out.println(rs5.getInt(1)+"t"+rs5.getString(2)+"t"+rs5.getInt(3)+"n");
- }
- break;
- case 11:
- String rj = "select * from employe e right outer join salary s on e.id=s.id";
- ResultSet rs6= stmnt.executeQuery(rj);
- System.out.println("IDtFnAMEtLNAME n");
- while(rs6.next())
- {
- System.out.println(rs6.getInt(1)+"t"+rs6.getString(2)+"t"+rs6.getString(3)+"n");
- }
- rj = "select * from employe e right outer join salary s on e.id=s.id";
- rs6= stmnt.executeQuery(rj);
- System.out.println("IDtFnAMEtLNAME n");
- while(rs6.next())
- {
- System.out.println(rs6.getInt(1)+"t"+rs6.getString(2)+"t"+rs6.getString(3)+"n");
- }
- }
- System.out.println("Do you want to continue y/n :n");
- y = in.nextLine();
- }while(y=="y");
- }
- catch(SQLException e)
- {
- System.err.println("Cannot Connect to the dbn");
- e.printStackTrace();
- }
- finally
- {
- System.out.println("Closing connection.......n");
- if(con!=null)
- {
- try
- {
- con.close();
- }
- catch(SQLException ig)
- {}
- }
- }
- }
- }
- mysql1.java:66: error: cannot find symbol
- PreparedStatement pstmnt = con.preparedStatement("insert into employe values(?,?,?)");
- ^
- symbol: method preparedStatement(String)
- location: variable con of type Connection
- mysql1.java:67: error: cannot find symbol
- pstmnt = setInt(1,id);
- ^
- symbol: method setInt(int,int)
- location: class mysql1
- mysql1.java:68: error: cannot find symbol
- pstmnt = setString(2,f);
- ^
- symbol: method setString(int,String)
- location: class mysql1
- mysql1.java:69: error: cannot find symbol
- pstmnt = setString(3,f);
- ^
- symbol: method setString(int,String)
- location: class mysql1
- mysql1.java:73: error: cannot find symbol
- }while(ans=='y');
- ^
- symbol: variable ans
- location: class mysql1
- mysql1.java:84: error: cannot find symbol
- PreparedStatement pstmnt = con.preparedStatement("insert into salary values(?,?,?)");
- ^
- symbol: method preparedStatement(String)
- location: variable con of type Connection
- mysql1.java:85: error: cannot find symbol
- pstmnt = setInt(1,id);
- ^
- symbol: variable id
- location: class mysql1
- mysql1.java:86: error: cannot find symbol
- pstmnt = setString(2,f);
- ^
- symbol: variable f
- location: class mysql1
- mysql1.java:87: error: cannot find symbol
- pstmnt = setInt(3,f);
- ^
- symbol: variable f
- location: class mysql1
- mysql1.java:91: error: cannot find symbol
- }while(ans=='y');
- ^
- symbol: variable ans
- location: class mysql1
- mysql1.java:119: error: cannot find symbol
- PreparedStatement ps = con.preparedStatement(updat);
- ^
- symbol: method preparedStatement(String)
- location: variable con of type Connection
- mysql1.java:130: error: cannot find symbol
- PreparedStatement ps1 = con.PreparedStatement(del);
- ^
- symbol: method PreparedStatement(String)
- location: variable con of type Connection
- mysql1.java:169: error: cannot find symbol
- inner1 = "select * from salary sal employe e on sal.id=e.id";
- ^
- symbol: variable inner1
- location: class mysql1
- mysql1.java:170: error: cannot find symbol
- rs5 = stmnt.executeQuery(inner1);
- ^
- symbol: variable inner1
- location: class mysql1
- 14 errors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement