Guest User

Untitled

a guest
Nov 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.Driver;
  3. import java.sql.DriverManager;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.Statement;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9. import java.sql.Connection;
  10. import java.sql.Driver;
  11. import java.sql.DriverManager;
  12. import java.sql.PreparedStatement;
  13. import java.sql.ResultSet;
  14. import java.sql.Statement;
  15. import java.util.logging.Level;
  16. import java.util.logging.Logger;
  17.  
  18. /*
  19. * To change this license header, choose License Headers in Project Properties.
  20. * To change this template file, choose Tools | Templates
  21. * and open the template in the editor.
  22. */
  23.  
  24. /**
  25. *
  26. * @author sunil */
  27. public class NewClass {
  28. public static void main(String[] args) {
  29. try{
  30. PreparedStatement ps=null;
  31. Connection cn=null;
  32.  
  33. ResultSet out=null;
  34. Class.forName("org.postgresql.Driver");
  35. cn=DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "1234");
  36. String str="select count(*) from student";
  37. ps=cn.prepareStatement(str);
  38. cn.close();
  39.  
  40. }
  41. catch(Exception e){
  42. System.out.println(e.toString());
  43. }
  44. }
  45.  
  46. }
  47.  
  48.  
  49. /*
  50. * To change this license header, choose License Headers in Project Properties.
  51. * To change this template file, choose Tools | Templates
  52. * and open the template in the editor.
  53. */
  54.  
  55. /**
  56. *
  57. * @author sunil
  58. */
  59. public class NewClass {
  60. public static void main(String[] args) {
  61. try{
  62. PreparedStatement ps=null;
  63. Connection cn=null;
  64.  
  65. ResultSet out=null;
  66. Class.forName("org.postgresql.Driver");
  67. cn=DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "1234");
  68. //String str="select count(*) from student";
  69. String str="select avg(maths),avg(science),avg(english) from student";
  70. ps=cn.prepareStatement(str);
  71. cn.close();
  72.  
  73. }
  74. catch(Exception e){
  75. System.out.println(e.toString());
  76. }
  77. }
  78.  
  79. }
Add Comment
Please, Sign In to add comment