Guest User

Untitled

a guest
Jan 5th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. package uk.ac.ebi.lnetdb.core;
  2.  
  3. import uk.ac.ebi.lnetdb.db.accessors.Fatty_acid_speciesTableAccessor;
  4. import uk.ac.ebi.lnetdb.utilities.readers.FattyAcidConstraints;
  5.  
  6. import java.io.InputStream;
  7. import java.sql.Connection;
  8. import java.sql.Driver;
  9. import java.sql.SQLException;
  10. import java.util.HashMap;
  11. import java.util.Properties;
  12.  
  13. /**
  14. * Created by IntelliJ IDEA.
  15. * User: jfoster
  16. * Date: 20-Apr-2011
  17. * Time: 16:45:15
  18. * To change this template use File | Settings | File Templates.
  19. */
  20. public class PopulateFATable {
  21. public static void main(String[] args) {
  22. try{
  23. Driver driver = (Driver)Class.forName("com.mysql.jdbc.Driver").newInstance();
  24. Properties props = new Properties();
  25. //props.put("user", "xxxx");
  26. //props.put("password", "xxxx");
  27. props.put("user", "xxx");
  28. props.put("password", "xxxx");
  29. //Connection con = driver.connect("jdbc:mysql://mysql-lnet.ebi.ac.uk:4265/lnetdb", props);
  30. try{
  31. Connection con = driver.connect("jdbc:mysql://localhost:3306/lnetdb", props);
  32.  
  33. con.setAutoCommit(false);
  34. StaticConnectionManager.setConnection(con);
  35. InputStream facis = PopulateFATable.class.getClassLoader().getResourceAsStream("fattyAcidConstraints.txt");
  36.  
  37. FattyAcidConstraints fac = new FattyAcidConstraints(facis);
  38. HashMap<String, Integer> facHM = fac.getiFattyAcidConstaints();
  39. Integer maxCarbons = facHM.get("maxCarbons");
  40. Integer minCarbons = facHM.get("minCarbons");
  41. Integer maxDoubleBonds = facHM.get("maxDoubleBonds");
  42. Integer minDoubleBonds = facHM.get("minDoubleBonds");
  43. Long fasPKCount = 0l;
  44.  
  45. //iterate FA results
  46.  
  47. for (Object o : facHM.keySet()) {
  48. Fatty_acid_speciesTableAccessor fasta = new Fatty_acid_speciesTableAccessor();
  49. fasta.setCarbons(o.getCarbons());
  50. fasta.setDouble_bonds(o.getDoubleBonds());
  51. fasta.setName(o.getName());
  52. fasta.setValidated(false);
  53. fasta.setFatty_acid_species_id(fasPKCount);
  54. fasPKCount++;
  55. fasta.persist(con);
  56.  
  57. }
  58. con.commit();
  59. }catch (SQLException e){
  60. e.printStackTrace();
  61. }
  62.  
  63. }catch(Exception e1){
  64. e1.printStackTrace();
  65. }
  66. }
  67. }
Add Comment
Please, Sign In to add comment