- package sql_lab;
- import java.sql.*;
- /*
- * 数据库操作接口类
- */
- public class sqlManager {
- private static final String SQL_CLASSPATH="org.gjt.mm.mysql.Driver";
- private static final String SQL_URL="jdbc:mysql://222.201.145.113:3306/shop";
- private static final String SQL_USER="guo";
- private static final String SQL_PASSWORD="password";
- //tables
- public static final String tb_producer="producer";
- public static final String tb_produce="produce";
- public static final String tb_repair="repair";
- public static final String tb_sell="sell";
- public static final String tb_store="store";
- public static final String tb_customer="customer";
- public static final String tb_user="user";
- public static final String tb_repair_shop="repair_shop";
- public static final String tb_fitting_result="result";
- /*
- * row
- */
- // table sell
- public static final String row_sell_id="sell_id";
- public static final String row_sell_store_id="sell_store_id";
- public static final String row_sell_produce_id="sell_produce_id";
- public static final String row_sell_customer_id="sell_customer_id";
- public static final String row_sell_amount="sell_amount";
- public static final String row_sell_time="sell_time";
- //table store
- public static final String row_store_id="store_id";
- public static final String row_store_name="store_name";
- public static final String row_store_address="store_address";
- public static final String row_store_keeper="store_keeper";
- public static final String row_store_call="store_call";
- //table customer
- public static final String row_customer_id="customer_id";
- public static final String row_customer_name="customer_name";
- public static final String row_customer_address="customer_address";
- public static final String row_customer_call="customer_call";
- public static final String row_customer_mail="customer_mail";
- public static final String row_customer_register="customer_register";
- //table produce
- public static final String row_produce_id="produce_id";
- public static final String row_produce_name="produce_name";
- public static final String row_produce_funtion="produce_funtion";
- public static final String row_produce_price="produce_price";
- public static final String row_produce_sort="produce_sort";
- public static final String row_produce_producer_id="producer_id";
- //table producer
- public static final String row_producer_id="producer_id";
- public static final String row_producer_name="producer_name";
- public static final String row_producer_address="producer_address";
- public static final String row_producer_call="producer_call";
- public static final String row_producer_describe="producer_describe";
- //table repair
- public static final String row_repair_id="repair_id";
- public static final String row_repair_time="repair_time";
- public static final String row_repair_information="repair_information";
- public static final String row_repair_produce_id="repair_produce_id";
- public static final String row_repair_customer_id="repair_customer_id";
- public static final String row_repair_repair_shop_id="repair_repair_shop_id";
- //talbe repair_shop
- public static final String row_repair_shop_id="repair_shop_id";
- public static final String row_repair_shop_name="repair_shop_name";
- public static final String row_repair_shop_address="repair_shop_address";
- public static final String row_repair_shop_keeper="repair_shop_keeper";
- public static final String row_repair_shop_call="repair_shop_call";
- //table result
- public static final String row_result_id="id";
- private static Connection dbConn=null;
- private static Statement statement=null;
- public static sqlManager sqlManager=null;
- private sqlManager(){
- try{
- Class.forName(sqlManager.SQL_CLASSPATH).newInstance();
- dbConn=DriverManager.getConnection(SQL_URL,SQL_USER,SQL_PASSWORD);
- statement=dbConn.createStatement();
- System.out.println("Connection successful ");
- }
- catch(Exception e){
- e.printStackTrace();
- }
- }
- public static sqlManager getSqlManager(){
- if(null==sqlManager.sqlManager)
- sqlManager=new sqlManager();
- return sqlManager.sqlManager;
- }
- public ResultSet executeQuery(String sql){
- ResultSet rs=null;
- try{
- rs=statement.executeQuery(sql);
- }
- catch(SQLException se){
- System.out.println("executeQuery error"+se.getMessage());
- }
- return rs;
- }
- public int executeUpdate(String sql){
- int count=0;
- try{
- count=statement.executeUpdate(sql);//执行更新操作
- }
- catch(SQLException sqle){
- System.out.println("executeUpdate error"+sqle.getMessage());
- count=0;
- }
- return count;
- }
- public static void closeSqlManager(){
- if(null!=sqlManager.sqlManager){
- try{
- statement.close();
- dbConn.close();
- }
- catch(Exception e){
- e.printStackTrace();
- }
- }
- }
- }