daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package assign3;
  2.  
  3. import java.sql.Statement;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8.  
  9. import javax.swing.table.AbstractTableModel;
  10.  
  11. public class MyDB extends AbstractTableModel {
  12.    
  13.     private Connection conn;
  14.     private Statement stm;
  15.     private ResultSet resSet;
  16.     private String url = "jdbc:mysql://"+MyDBInfo.MYSQL_DATABASE_SERVER;
  17.     private String user = MyDBInfo.MYSQL_USERNAME;
  18.     private String password = MyDBInfo.MYSQL_PASSWORD;
  19.    
  20.  
  21.     public static void main(String[] args) {
  22.         MyDB db = new MyDB();
  23.         System.out.println("nuts");
  24.     }
  25.    
  26.     public MyDB() {
  27.         try {
  28.             Class.forName("com.mysql.jdbc.Driver");
  29.         } catch (ClassNotFoundException e1) {
  30.             // TODO Auto-generated catch block
  31.             e1.printStackTrace();
  32.         }
  33.         try {
  34.             conn = DriverManager.getConnection(url, user, password);
  35.             stm = (Statement) conn.createStatement();
  36.         } catch (SQLException e) {
  37.             // TODO Auto-generated catch block
  38.             e.printStackTrace();
  39.         }
  40.     }
  41.    
  42.     public void add(String Metropolis, String Continent, String Population) {
  43.         String q1 = "INSERT INTO metropolises VALUES(\""
  44.                     + Metropolis + "\", \"" + Continent + "\", \"" + Population + "\"";  
  45.         try {
  46.             stm.executeUpdate(q1);
  47.         } catch (SQLException e) {
  48.             // TODO Auto-generated catch block
  49.             e.printStackTrace();
  50.         }
  51.     }
  52.    
  53.     public void search(String Metropolis, String Continent, String Population, String Condition, Boolean Accuracy) {
  54.         String l1 = "SELECT * FROM metropolisis";
  55.         Metropolis = Metropolis == "" ? "%%" : Metropolis;
  56.         Continent = Continent == "" ? "%%" : Continent;
  57.         if(Accuracy == false) {
  58.             Metropolis = "%" + Metropolis + "%";
  59.             Continent = "%" + Continent + "%";
  60.         }
  61.         String l2 = "WHERE Metropolis like \"" + Metropolis + "\"";
  62.         String l3 = " AND Continent like \"" + Continent + "\"";
  63.         String l4 = "";
  64.         if(Population.matches("[0-9]+")) {
  65.             l4 = " AND Population like \"" + Continent + "\"";
  66.         }
  67.         try {
  68.             resSet = stm.executeQuery(l1 + l2 + l3 + l4);
  69.         } catch (SQLException e) {
  70.             // TODO Auto-generated catch block
  71.             e.printStackTrace();
  72.         }
  73.     }
  74.  
  75.     @Override
  76.     public int getRowCount() {
  77.         // TODO Auto-generated method stub
  78.         return 0;
  79.     }
  80.  
  81.     @Override
  82.     public int getColumnCount() {
  83.         // TODO Auto-generated method stub
  84.         return 0;
  85.     }
  86.  
  87.     @Override
  88.     public Object getValueAt(int rowIndex, int columnIndex) {
  89.         // TODO Auto-generated method stub
  90.         return null;
  91.     }
  92.    
  93.  
  94. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top