Advertisement
Guest User

Untitled

a guest
Oct 16th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.83 KB | None | 0 0
  1. I have tried the solutions on stackoverflow but it didnt solve my problem so i would like to ask it
  2. import java.*;
  3. import java.lang.*;
  4. import java.sql.*;
  5. import java.io.*;
  6. import java.util.*;
  7. public class mysql1
  8. {
  9. static final String url = "jdbc:mysql://localhost:3306/test";
  10. static final String usr = "root";
  11. static final String passwd = "";
  12. public static void main(String [] ar)
  13. {
  14. Connection con = null;
  15. // boolean flag = True;
  16. int ch;
  17. String y;
  18. try
  19. {
  20. System.out.println("connecting to db...n");
  21. con = DriverManager.getConnection(url,usr,passwd);
  22. System.out.println("Database Connected.n");
  23. CallableStatement cs = null;
  24. Statement stmnt = con.createStatement();
  25. do
  26. {
  27. Scanner in = new Scanner(System.in);
  28. System.out.println("1.Create Tablen");
  29. System.out.println("2.Insert Tablen");
  30. System.out.println("3.Display Tablen");
  31. System.out.println("4.Update Tablen");
  32. System.out.println("5.Delete Tablen");
  33. System.out.println("6.Creating indexn");
  34. System.out.println("7.Show indexn");
  35. System.out.println("8.Create Viewn");
  36. System.out.println("9.Show viewn");
  37. System.out.println("10. Inner Joinn");
  38. System.out.println("11. Right outer joinn");
  39. System.out.println("12. Left outer joinn");
  40. System.out.println("13. Cross joinn");
  41. System.out.println("14. Exitn");
  42. System.out.println("Enter your choice");
  43. ch = in.nextInt();
  44. switch(ch)
  45. {
  46. case 1:
  47. System.out.println("Creating table 1.n");
  48. String t1 = "create table employe(id int(10),"+"fname varchar(20),"+"lname varchar(15))";
  49. stmnt.executeUpdate(t1);
  50. System.out.println("Table 1 Created..n");
  51. System.out.println("Creating table 2.n");
  52. String t2 = "create table salary(id int(10),"+"fname varchar(20),"+"salray int(10))";
  53. stmnt.executeUpdate(t2);
  54. System.out.println("Table 2 Created..n");
  55. break;
  56. case 2:
  57. System.out.println("Entering data in 1st tablen");
  58. do
  59. {
  60. System.out.println("Enter id:n");
  61. int id = in.nextInt();
  62. String str = in.nextLine();
  63. System.out.println("Enter respective fname:n");
  64. String f = in.nextLine();
  65. System.out.println("Enter lname:n");
  66. String l = in.nextLine();
  67. PreparedStatement pstmnt = con.preparedStatement("insert into employe values(?,?,?)");
  68. pstmnt = setInt(1,id);
  69. pstmnt = setString(2,f);
  70. pstmnt = setString(3,f);
  71. pstmnt.executeUpdate();
  72. System.out.println("Do you want to continue? y/n");
  73. String ans = in.nextLine();
  74. }while(ans=='y');
  75. System.out.println("Entering data in 2nd tablen");
  76. do
  77. {
  78. System.out.println("Enter id:n");
  79. int id1 = in.nextInt();
  80. String str1 = in.nextLine();
  81. System.out.println("Enter respective fname:n");
  82. String f1 = in.nextLine();
  83. System.out.println("Enter the salaryn");
  84. int sal = in.nextInt();
  85. PreparedStatement pstmnt = con.preparedStatement("insert into salary values(?,?,?)");
  86. pstmnt = setInt(1,id);
  87. pstmnt = setString(2,f);
  88. pstmnt = setInt(3,f);
  89. pstmnt.executeUpdate();
  90. System.out.println("Do you want to continue? y/n");
  91. String ans = in.nextLine();
  92. }while(ans=='y');
  93. break;
  94. case 3:
  95. System.out.println("Displaying Table 1.....n");
  96. String display = "select * from employe";
  97. ResultSet rs1 = stmnt.executeQuery(display);
  98. System.out.println("ID t FNAME t LNAME");
  99. while(rs1.next())
  100. {
  101. System.out.println(rs1.getInt(1)+"t"+rs1.getString(2)+"t"+rs1.getString(3));
  102. }
  103. System.out.println("Displaying Table 2.....n");
  104. String display1 = "select * from salary";
  105. ResultSet rs4 = stmnt.executeQuery(display);
  106. System.out.println("ID t FNAME t SALARY");
  107. while(rs4.next())
  108. {
  109. System.out.println(rs4.getInt(1)+"t"+rs4.getString(2)+"t"+rs4.getInt(3));
  110. }
  111. break;
  112. case 4:
  113. String updat = "update employe set fname=?, lname=? where id=?";
  114. System.out.println("Enter the id of the employe that you want to update:n");
  115. int id1 = in.nextInt();
  116. System.out.println("Enter new fname:n");
  117. String f1 = in.nextLine();
  118. System.out.println("Enter new lname:n");
  119. String l1 = in.nextLine();
  120. PreparedStatement ps = con.preparedStatement(updat);
  121. ps.setString(1,f1);
  122. ps.setString(2,l1);
  123. ps.setInt(3,id1);
  124. ps.executeUpdate();
  125. break;
  126. case 5:
  127. System.out.println("Delete enteries from table using id......n");
  128. String del = "delete from employe where id=?";
  129. System.out.println("Enter the ID:n");
  130. int id2 = in.nextInt();
  131. PreparedStatement ps1 = con.PreparedStatement(del);
  132. ps1.setInt(1,id2);
  133. ps.executeUpdate();
  134. break;
  135. case 6:
  136. System.out.println("Creating Index.....n");
  137. String ind = "create index inde on employe(fname)";
  138. stmnt.executeUpdate(ind);
  139. System.out.println("Index created .....n");
  140. break;
  141. case 7:
  142. System.out.println("Display index.....n");
  143. String inde = "show index from employe";
  144. ResultSet rs2 = stmnt.executeQuery(inde);
  145. 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");
  146. break;
  147. case 8:
  148. System.out.println("Create view......n");
  149. String vew = "create view v1 as select id,lname from employe";
  150. stmnt.executeUpdate(vew);
  151. System.out.println("View createdn");
  152. break;
  153. case 9:
  154. System.out.println("Displaying View......n");
  155. String disv = "select * from v1";
  156. ResultSet rs3 = stmnt.executeQuery(disv);
  157. while(rs3.next())
  158. {
  159. System.out.println(rs3.getInt(1)+"t"+rs3.getString(2));
  160. }
  161. break;
  162. case 10:
  163. String inner = "select * from employe e inner join salary sa on e.id=sa.id";
  164. ResultSet rs5 = stmnt.executeQuery(inner);
  165. System.out.println("IDtFNMEtlnamen");
  166. while(rs5.next())
  167. {
  168. System.out.println(rs5.getInt(1)+"t"+rs5.getString(2)+"t"+rs5.getString(3)+"n");
  169. }
  170. inner1 = "select * from salary sal employe e on sal.id=e.id";
  171. rs5 = stmnt.executeQuery(inner1);
  172. System.out.println("IDtFNMEtSalaryn");
  173. while(rs5.next())
  174. {
  175. System.out.println(rs5.getInt(1)+"t"+rs5.getString(2)+"t"+rs5.getInt(3)+"n");
  176. }
  177. break;
  178. case 11:
  179. String rj = "select * from employe e right outer join salary s on e.id=s.id";
  180. ResultSet rs6= stmnt.executeQuery(rj);
  181. System.out.println("IDtFnAMEtLNAME n");
  182. while(rs6.next())
  183. {
  184. System.out.println(rs6.getInt(1)+"t"+rs6.getString(2)+"t"+rs6.getString(3)+"n");
  185. }
  186. rj = "select * from employe e right outer join salary s on e.id=s.id";
  187. rs6= stmnt.executeQuery(rj);
  188. System.out.println("IDtFnAMEtLNAME n");
  189. while(rs6.next())
  190. {
  191. System.out.println(rs6.getInt(1)+"t"+rs6.getString(2)+"t"+rs6.getString(3)+"n");
  192. }
  193. }
  194. System.out.println("Do you want to continue y/n :n");
  195. y = in.nextLine();
  196. }while(y=="y");
  197. }
  198. catch(SQLException e)
  199. {
  200. System.err.println("Cannot Connect to the dbn");
  201. e.printStackTrace();
  202. }
  203. finally
  204. {
  205. System.out.println("Closing connection.......n");
  206. if(con!=null)
  207. {
  208. try
  209. {
  210. con.close();
  211. }
  212. catch(SQLException ig)
  213. {}
  214. }
  215. }
  216. }
  217. }
  218.  
  219. mysql1.java:66: error: cannot find symbol
  220. PreparedStatement pstmnt = con.preparedStatement("insert into employe values(?,?,?)");
  221. ^
  222. symbol: method preparedStatement(String)
  223. location: variable con of type Connection
  224. mysql1.java:67: error: cannot find symbol
  225. pstmnt = setInt(1,id);
  226. ^
  227. symbol: method setInt(int,int)
  228. location: class mysql1
  229. mysql1.java:68: error: cannot find symbol
  230. pstmnt = setString(2,f);
  231. ^
  232. symbol: method setString(int,String)
  233. location: class mysql1
  234. mysql1.java:69: error: cannot find symbol
  235. pstmnt = setString(3,f);
  236. ^
  237. symbol: method setString(int,String)
  238. location: class mysql1
  239. mysql1.java:73: error: cannot find symbol
  240. }while(ans=='y');
  241. ^
  242. symbol: variable ans
  243. location: class mysql1
  244. mysql1.java:84: error: cannot find symbol
  245. PreparedStatement pstmnt = con.preparedStatement("insert into salary values(?,?,?)");
  246. ^
  247. symbol: method preparedStatement(String)
  248. location: variable con of type Connection
  249. mysql1.java:85: error: cannot find symbol
  250. pstmnt = setInt(1,id);
  251. ^
  252. symbol: variable id
  253. location: class mysql1
  254. mysql1.java:86: error: cannot find symbol
  255. pstmnt = setString(2,f);
  256. ^
  257. symbol: variable f
  258. location: class mysql1
  259. mysql1.java:87: error: cannot find symbol
  260. pstmnt = setInt(3,f);
  261. ^
  262. symbol: variable f
  263. location: class mysql1
  264. mysql1.java:91: error: cannot find symbol
  265. }while(ans=='y');
  266. ^
  267. symbol: variable ans
  268. location: class mysql1
  269. mysql1.java:119: error: cannot find symbol
  270. PreparedStatement ps = con.preparedStatement(updat);
  271. ^
  272. symbol: method preparedStatement(String)
  273. location: variable con of type Connection
  274. mysql1.java:130: error: cannot find symbol
  275. PreparedStatement ps1 = con.PreparedStatement(del);
  276. ^
  277. symbol: method PreparedStatement(String)
  278. location: variable con of type Connection
  279. mysql1.java:169: error: cannot find symbol
  280. inner1 = "select * from salary sal employe e on sal.id=e.id";
  281. ^
  282. symbol: variable inner1
  283. location: class mysql1
  284. mysql1.java:170: error: cannot find symbol
  285. rs5 = stmnt.executeQuery(inner1);
  286. ^
  287. symbol: variable inner1
  288. location: class mysql1
  289. 14 errors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement