sqlManager.java
上传用户:flow_meter
上传日期:2022-03-21
资源大小:40k
文件大小:5k
源码类别:

MySQL数据库

开发平台:

SQL

  1. package sql_lab;
  2. import java.sql.*;
  3. /*
  4.  * 数据库操作接口类
  5.  */
  6. public class sqlManager {
  7. private static final String SQL_CLASSPATH="org.gjt.mm.mysql.Driver";
  8. private static final String SQL_URL="jdbc:mysql://222.201.145.113:3306/shop"; 
  9. private static final String SQL_USER="guo";
  10. private static final String SQL_PASSWORD="password";
  11. //tables
  12. public static final String tb_producer="producer";
  13. public static final String tb_produce="produce";
  14. public static final String tb_repair="repair";
  15. public static final String tb_sell="sell";
  16. public static final String tb_store="store";
  17. public static final String tb_customer="customer";
  18. public static final String tb_user="user";
  19. public static final String tb_repair_shop="repair_shop";
  20. public static final String tb_fitting_result="result";
  21. /*
  22.  * row
  23.  */
  24. // table sell
  25. public  static final String row_sell_id="sell_id";
  26. public  static final String row_sell_store_id="sell_store_id";
  27. public  static final String row_sell_produce_id="sell_produce_id";
  28. public  static final String row_sell_customer_id="sell_customer_id";
  29. public  static final String row_sell_amount="sell_amount";
  30. public  static final String row_sell_time="sell_time";
  31. //table store
  32. public  static final String row_store_id="store_id";
  33. public  static final String row_store_name="store_name";
  34. public  static final String row_store_address="store_address";
  35. public  static final String row_store_keeper="store_keeper";
  36. public  static final String row_store_call="store_call";
  37. //table customer
  38. public  static final String row_customer_id="customer_id";
  39. public  static final String row_customer_name="customer_name";
  40. public  static final String row_customer_address="customer_address";
  41. public  static final String row_customer_call="customer_call";
  42. public  static final String row_customer_mail="customer_mail";
  43. public  static final String row_customer_register="customer_register";
  44. //table produce
  45. public  static final String row_produce_id="produce_id";
  46. public  static final String row_produce_name="produce_name";
  47. public  static final String row_produce_funtion="produce_funtion";
  48. public  static final String row_produce_price="produce_price";
  49. public  static final String row_produce_sort="produce_sort";
  50. public  static final String row_produce_producer_id="producer_id";
  51. //table producer
  52. public  static final String row_producer_id="producer_id";
  53. public  static final String row_producer_name="producer_name";
  54. public  static final String row_producer_address="producer_address";
  55. public  static final String row_producer_call="producer_call";
  56. public  static final String row_producer_describe="producer_describe";
  57. //table repair
  58. public  static final String row_repair_id="repair_id";
  59. public  static final String row_repair_time="repair_time";
  60. public  static final String row_repair_information="repair_information";
  61. public  static final String row_repair_produce_id="repair_produce_id";
  62. public  static final String row_repair_customer_id="repair_customer_id";
  63. public  static final String row_repair_repair_shop_id="repair_repair_shop_id";
  64. //talbe repair_shop
  65. public  static final String row_repair_shop_id="repair_shop_id";
  66. public  static final String row_repair_shop_name="repair_shop_name";
  67. public  static final String row_repair_shop_address="repair_shop_address";
  68. public  static final String row_repair_shop_keeper="repair_shop_keeper";
  69. public  static final String row_repair_shop_call="repair_shop_call";
  70. //table result
  71. public  static final String row_result_id="id";
  72. private static Connection dbConn=null;
  73. private static Statement statement=null;
  74. public static sqlManager sqlManager=null;
  75. private sqlManager(){
  76. try{
  77. Class.forName(sqlManager.SQL_CLASSPATH).newInstance();
  78. dbConn=DriverManager.getConnection(SQL_URL,SQL_USER,SQL_PASSWORD);
  79. statement=dbConn.createStatement();
  80. System.out.println("Connection successful ");
  81. }
  82. catch(Exception e){
  83. e.printStackTrace();
  84. }
  85. }
  86. public static sqlManager getSqlManager(){
  87. if(null==sqlManager.sqlManager)
  88. sqlManager=new sqlManager();
  89. return sqlManager.sqlManager;
  90. }
  91. public  ResultSet executeQuery(String sql){
  92. ResultSet rs=null;
  93. try{
  94. rs=statement.executeQuery(sql);
  95. }
  96. catch(SQLException se){
  97. System.out.println("executeQuery error"+se.getMessage());
  98. }
  99. return rs;
  100. }
  101. public int executeUpdate(String sql){
  102. int count=0;
  103. try{
  104. count=statement.executeUpdate(sql);//执行更新操作
  105. }
  106. catch(SQLException sqle){
  107. System.out.println("executeUpdate error"+sqle.getMessage());
  108. count=0;
  109. }
  110. return count;
  111. }
  112. public static void closeSqlManager(){
  113. if(null!=sqlManager.sqlManager){
  114. try{
  115. statement.close();
  116. dbConn.close();
  117. }
  118. catch(Exception e){
  119. e.printStackTrace();
  120. }
  121. }
  122. }
  123. }