Advertisement
Guest User

Untitled

a guest
Mar 12th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.10 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package newschecksqlserver;
  7.  
  8. /**
  9. *
  10. * @author Jay Khurana
  11. */
  12.  
  13. import com.mashape.unirest.http.HttpResponse;
  14. import com.mashape.unirest.http.JsonNode;
  15. import com.mashape.unirest.http.Unirest;
  16. import com.mashape.unirest.http.exceptions.UnirestException;
  17. import java.awt.Color;
  18. import java.math.BigInteger;
  19. import java.util.*;
  20. //TODO import JDBC driver
  21. import java.net.URI;
  22. import java.net.URISyntaxException;
  23. import java.net.URL;
  24. import java.net.URLConnection;
  25. import java.net.URLEncoder;
  26. import java.sql.Connection;
  27. import java.sql.DriverManager;
  28. import java.sql.ResultSet;
  29. import java.sql.SQLException;
  30. import java.sql.Statement;
  31. import java.text.DateFormat;
  32. import java.text.SimpleDateFormat;
  33. import java.util.logging.Level;
  34. import java.util.logging.Logger;
  35. import javax.swing.JOptionPane;
  36. import javax.swing.table.DefaultTableModel;
  37. import org.json.JSONArray;
  38.  
  39. public class NewsUpdater {
  40.  
  41. //TODO add webhose api array and current index, intialize in main
  42. private static Connection con;
  43. private static final String [] webhoseTokens = {"f299c8df-c58a-4757-8044-b31313786022"};
  44. private static int tokenChoice = 0;
  45.  
  46. public static void main(String[] args) {
  47. // TODO code application logic here
  48. //retrieveAndParseWebhose(0);
  49. //updateTable(null);
  50. //runRetrieval();
  51. try{
  52. connectToSQL();
  53. }catch(Exception exe){
  54. System.out.println("Error Connecting to SQL");
  55. return;
  56. }
  57. /* String query = "INSERT INTO dbo.ARTICLES values('652222dd9e931e304f667d6fbfabe36c023bb18f', 1486284741492, 'go.com' , 72, 0.0, NULL, NULL, 25, NULL)";
  58. try (Statement stmt = con.createStatement()) {
  59. stmt.executeUpdate(query);
  60. }catch(Exception exe){
  61. System.out.println();
  62. }*/
  63. /*
  64. // INITIAL CODE I RAN TO SET UP THE TABLES IN THE DATABASES
  65. try{
  66. createArticlesTable();
  67. }catch(Exception exe){
  68. System.out.println("Error creating SQL table");
  69. return;
  70. }
  71. try{
  72. createLookupTable();
  73. }catch(Exception exe){
  74. System.out.println("Error creating SQL table");
  75. return;
  76. } */
  77. long round = 0;
  78. while(true){
  79. System.out.println("Scraping round "+ round++);
  80. long unixTime = System.currentTimeMillis();
  81. retrieveAndParseWebhose(unixTime-1000*300); //TODO ERROR CHECK
  82. try {
  83. Thread.sleep(1000*5*60);
  84. } catch (InterruptedException ex) {
  85. Logger.getLogger(NewsUpdater.class.getName()).log(Level.SEVERE, null, ex);
  86. }
  87. }
  88. }
  89.  
  90. /**
  91. * Queries webhose every 5 minutes to get latest news updates
  92. */
  93. private static void runRetrieval(){
  94. //WHILE TRUE:
  95. //call retrieveAndParseWebhose(TS);
  96. //start new thread for processing webhose query
  97. //sleep 5 minutes
  98. }
  99.  
  100. /**
  101. * Retrieves all news data after a given unix timestamp
  102. * @param timestamp
  103. * @return a List of List of Strings to be added to the SQL table
  104. */
  105. private static void retrieveAndParseWebhose(long timestamp){
  106. String token = webhoseTokens[tokenChoice++];
  107. tokenChoice = tokenChoice % webhoseTokens.length;
  108. String request = "http://webhose.io/search?token="+token+"&format=json&q=%20language%3A(english)%20(site_type%3Anews)%20domain_rank%3A%3C100&ts="+timestamp;
  109. try{
  110. //String link = "http://webhose.io/search?token=f299c8df-c58a-4757-8044-b31313786022&format=json&q=language%3A(english)%20(site_type%3Anews)%20domain_rank%3A%3C100&ts=1486263054470";
  111. HttpResponse<JsonNode> response = Unirest.get(request).header("Accept", "text/plain").asJson();
  112. System.out.println();
  113. AsyncProc async = new AsyncProc(response);
  114. async.run();
  115. }catch(UnirestException exe){
  116. exe.printStackTrace();
  117. System.out.println("Exception occured while parsing shit\n");
  118. }catch(Exception exe){
  119. exe.printStackTrace();
  120. System.out.println();
  121. }
  122. }
  123.  
  124. public static void updateTables(List<List<Object>> cells){
  125. String connectionUrl = "jdbc:sqlserver://newzcheck.cnvyumwrcz7i.us-east-1.rds.amazonaws.com:1433;"
  126. + "databaseName=verifiednews;user=allAccess;password=xFz23d4a3Ln5dZ5sW";
  127. try {
  128.  
  129. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  130. Connection con = DriverManager.getConnection(connectionUrl);
  131. String sqlQuery = "SELECT CURRENT_VER, VER_URL "
  132. + "FROM dbo.UPDATES";
  133. Statement stmt;
  134. ResultSet rs;
  135. try {
  136. stmt = con.createStatement();
  137. rs = stmt.executeQuery(sqlQuery);
  138. rs.next();
  139. String verCheck = rs.getString(1);
  140. System.out.println("Check passed: " + verCheck);
  141. } catch (Exception exe) {
  142. System.out.println("Check failed");
  143. }
  144. con.close();
  145. } catch (ClassNotFoundException exe) {
  146. System.out.println("SQL Driver missing");
  147. } catch (Exception exe) {
  148. exe.printStackTrace();
  149. System.out.println("Other exception");
  150. }
  151. }
  152. //TODO: SEPERATE CLASS THAT RUNS OTHER SHIT
  153. //TODO: Asynchronous calls
  154.  
  155. private static void connectToSQL() throws Exception{
  156. String connectionUrl = "jdbc:sqlserver://newzcheck.database.windows.net:1433;database=verifiednews;user=allAccess@newzcheck;password={xFz23d4a3Ln5dZ5sW};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30";
  157. /*String connectionUrl = "jdbc:sqlserver:/newzcheck.database.windows.net:1433;"
  158. + "databaseName=verifiednews;user=allAccess;password=xFz23d4a3Ln5dZ5sW"; */
  159. //String connectionUrl="jdbc:sqlserver://localhost:1433;"
  160. // + "databaseName=Genes;user=sa;password=12345";
  161. try{
  162. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  163. con = DriverManager.getConnection(connectionUrl);
  164. }catch(ClassNotFoundException | SQLException exe){
  165. throw exe;
  166. }
  167. }
  168.  
  169. //Retrieves data from SQL
  170. private static void retrieveDataFromSQL() throws Exception{
  171. /*
  172. String sqlQuery="SELECT PROT_FASTA, NUCLEO_FASTA, "
  173. + "PARA_PROT_ALI, PARA_NUCLEO_ALI, HOMO_PROT_ALI, "
  174. + "HOMO_NUCLEO_ALI FROM dbo." +gene.toUpperCase().replace("-", "") +" ORDER BY PRIM_KEY";
  175. Statement stmt;
  176. ResultSet rs;
  177. stmt=con.createStatement();
  178. rs=stmt.executeQuery(sqlQuery);
  179. String protFasta=null, nucleoFasta=null, nID=null, pID=null;
  180. try{
  181. rs.next();
  182. protFasta=rs.getString(1);
  183. nucleoFasta=rs.getString(2);
  184. aFasta=protFasta.substring(protFasta.indexOf("\n")+1,protFasta.length()-1);
  185. tempDNA=nucleoFasta.substring(nucleoFasta.indexOf("\n")+1,nucleoFasta.length()-1);
  186. pFasta2=rs.getString(3);
  187. nFasta2=rs.getString(4);
  188. pFasta=rs.getString(5);
  189. nFasta=rs.getString(6);
  190. if(pFasta==null||pFasta.equals("")){
  191. if(b!=null)
  192. b.addError(gene.toUpperCase()+" has neither orthologous or "
  193. + "paralogous genes that could be found. "
  194. + "The nucleotide and protein sequences and other "
  195. + "gene information is still availible, however.");
  196. else
  197. JOptionPane.showMessageDialog(null, gene.toUpperCase()+" has neither orthologous or "
  198. + "paralogous genes that could be found. "
  199. + "The nucleotide and protein sequences and other "
  200. + "gene information is still availible, however.",
  201. "Warning", JOptionPane.WARNING_MESSAGE);
  202. }
  203. sqlQuery="SELECT GENE_PROPS FROM dbo." + gene.toUpperCase().replace("-", "") +
  204. " ORDER BY PRIM_KEY";
  205. rs=stmt.executeQuery(sqlQuery);
  206. geneProperties[0]=gene;
  207. for(int i=1; i<9; i++){
  208. rs.next();
  209. geneProperties[i]=rs.getString(1);
  210. }
  211. gene1=new Gene(gene,geneProperties[4],geneProperties[5],nucleoFasta,protFasta);
  212. model=(DefaultTableModel)table.getModel();
  213. tempSNPs=new SNP[5000];
  214. sqlQuery="SELECT SNP, SNP_PHENO, SNP_MULT, SNP_URL "
  215. + "FROM dbo." + gene.toUpperCase().replace("-", "") +
  216. " ORDER BY PRIM_KEY";
  217. rs=stmt.executeQuery(sqlQuery);
  218. while(rs.next()){
  219. String SNPID=rs.getString(1);
  220. String SNPPheno=rs.getString(2);
  221. String SNPMult=rs.getString(3);
  222. String SNPURL=rs.getString(4);
  223. if(SNPID==null)
  224. continue;
  225. if(SNPPheno==null)
  226. SNPPheno="Unknown";
  227. if(SNPMult==null)
  228. SNPMult="Not verified";
  229. try{
  230. SNP s = new SNP(SNPPheno, SNPID.substring(SNPID.length()-1, SNPID.length()),
  231. "",Integer.parseInt(SNPID.substring(1,SNPID.length()-1)),
  232. -1, false);
  233. s.setInfoURL(SNPURL);
  234. if(b==null)
  235. model.addRow(new Object[]{
  236. true,SNPID,SNPPheno,SNPMult,"Please Wait"});
  237. else
  238. model.addRow(new Object[]{
  239. false,SNPID,SNPPheno,SNPMult,"Please Wait"});
  240. tempSNPs[numClinicalSNPs++]=s;
  241. rowURL[numClinicalSNPs-1]=tempSNPs[numClinicalSNPs-1].getInfoUrl();
  242. }catch(NumberFormatException exe){
  243. continue;
  244. }
  245. }
  246. allSNPs = new SNP[5000];
  247. System.arraycopy(tempSNPs, 0, allSNPs, 0, numClinicalSNPs);
  248. geneURL=geneSearchURL=geneProperties[6];
  249. numHomologs=Integer.parseInt(geneProperties[7]);
  250. numParalogs=Integer.parseInt(geneProperties[8]);
  251. panel.setLabels(gene,geneProperties[1],""+geneProperties[2],
  252. geneProperties[3],geneProperties[4],geneProperties[5]);
  253. panel.enableGeneSequences();
  254. panel.infoReady();
  255. panel.enableParalogs();
  256. panel.stopWait();
  257. panel.enableMutationChecking();
  258. panel.stopWait2();
  259. panel.enableReport();
  260. panel.enableHomologs();
  261. }catch(SQLException | NumberFormatException exe){
  262. System.out.println("Gene read error "+gene);
  263. clearAll();
  264. throw exe;
  265. }finally{
  266. if(rs!=null)
  267. rs.close();
  268. stmt.close();
  269. }
  270. */
  271. }
  272.  
  273. //TODO CLOSE CONNECTION ON ERROR
  274. private static void createArticlesTable() throws Exception{
  275. String tableName = "ARTICLES";
  276. String cols =
  277. "CREATE TABLE dbo." +
  278. tableName +
  279. " ("+"UUID nchar(40) NOT NULL, " +
  280. "TS nvarchar(MAX), " +
  281. "SITE nvarchar(MAX), " +
  282. "TITLE nvarchar(MAX), " +
  283. "DOM_RANK int, " +
  284. "SPAM_SCORE float(4), " +
  285. "TEXT nvarchar(MAX), " +
  286. "COG_RESULTS nvarchar(MAX), " +
  287. "NUM_KEYWORDS tinyint, " +
  288. "MISC nvarchar(MAX), " +
  289. "PRIMARY KEY (UUID))";
  290. try (Statement stmt = con.createStatement()) {
  291. stmt.executeUpdate(cols);
  292. }catch(Exception exe){
  293. exe.printStackTrace();
  294. throw exe;
  295. }
  296. System.out.println("Table Created Sucesfully!");
  297. }
  298.  
  299. private static void createLookupTable() throws Exception{
  300. String tableName = "LOOKUP";
  301. String cols =
  302. "CREATE TABLE dbo." +
  303. tableName +
  304. " ("+"HASH nchar(44) NOT NULL, " +
  305. "UUID nchar(40), " +
  306. "TS nvarchar(MAX), " +
  307. "WORD nvarchar(MAX), " +
  308. "PRIMARY KEY (HASH))";
  309. try (Statement stmt = con.createStatement()) {
  310. stmt.executeUpdate(cols);
  311. }catch(Exception exe){
  312. exe.printStackTrace();
  313. throw exe;
  314. }
  315. }
  316.  
  317. public Object nullFix(Object o){
  318. try{
  319. return ((String)o.equals("")) ? "NULL", o;
  320. }catch(Exception exe){
  321. return o;
  322. }
  323. }
  324.  
  325. public List<Object> nullFixRow(List<Object> objs) {
  326. List<Object> row = new ArrayList<>();
  327. for (int i = 0; i < objs.length(); i++) {
  328. row.add(nullFix(objs.get(i)));
  329. }
  330. return row;
  331. }
  332.  
  333. public void setPreparedStatementValue(PreparedStatement p, int col, String type, Object value) {
  334. if value.equals("NULL") {
  335. if type.toLower().equals("string") {
  336. p.setNull(col, java.sql.Types.VARCHAR);
  337. }
  338. else if type.toLower().equals("int") {
  339. p.setNull(col, java.sql.Types.INTEGER);
  340. }
  341. else if type.toLower().equals("float") {
  342. p.setNull(col, java.sql.Types.FLOAT);
  343. }
  344. else {
  345. throw new Exception("Prepared statement null type not handled failure.");
  346. }
  347. }
  348. else {
  349. if type.toLower().equals("string") {
  350. p.setString(col, (String)value);
  351. }
  352. else if type.toLower().equals("int") {
  353. p.setInteger(col, (int)value);
  354. }
  355. else if type.toLower().equals("float") {
  356. p.setFloat(col, (float)value);
  357. }
  358. else {
  359. throw new Exception("Prepared statement type not handled failure.");
  360. }
  361. }
  362. }
  363.  
  364. public static void saveArticleToSQL(List<Object> articleInfo) {
  365. //0: UUID, 1: url, 2: publish_time
  366. List<Object> articleData = nullFixRow(articleInfo);
  367. try (preparedStatement = connection.prepareStatement("INSERT INTO dbo.Article VALUES (?, ?, ?, ?, ?, ? ,? ,? ,? ,? ,? ,? , ? ,? ,? ,?)");){
  368. for (int i = 0; i < 16 ; i++) {
  369. if (i < 2) {
  370. setPreparedStatementValue(preparedStatement, i, "string", (String)articleData.get(i));
  371. }
  372. else if (i < 5) {
  373. setPreparedStatementValue(preparedStatement, i, "int", (int)articleData.get(i));
  374. }
  375. else if (i < 12) {
  376. setPreparedStatementValue(preparedStatement, i, "string", (String)articleData.get(i));
  377. }
  378. else if (i < 13) {
  379. setPreparedStatementValue(preparedStatement, i, "float", (float)articleData.get(i));
  380. }
  381. else {
  382. setPreparedStatementValue(preparedStatement, i, "string", (String)articleData.get(i));
  383. }
  384. }
  385. preparedStatement.executeUpdate();
  386. } catch (SQLException e) {
  387. e.printStackTrace();
  388. }
  389. }
  390.  
  391. public static void saveOrganizationsToSQL(List<Object> organizationInfo) {
  392. //0: UUID, 1: url, 2: publish_time
  393. List<Object> organizationData = nullFixRow(articleInfo);
  394. try (preparedStatement = connection.prepareStatement("INSERT INTO dbo.Organizations VALUES (?, ?, ?)");){
  395. for (int i = 0; i < 3 ; i++) {
  396. setPreparedStatementValue(preparedStatement, i, "string", (String)organizationData.get(i));
  397. }
  398. }
  399. preparedStatement.executeUpdate();
  400. } catch (SQLException e) {
  401. e.printStackTrace();
  402. }
  403. }
  404.  
  405. public static void savePeopleToSQL(List<Object> peopleInfo) {
  406. //0: UUID, 1: url, 2: publish_time
  407. List<Object> peopleData = nullFixRow(peopleInfo);
  408. try (preparedStatement = connection.prepareStatement("INSERT INTO dbo.People VALUES (?, ?, ?)");){
  409. for (int i = 0; i < 3 ; i++) {
  410. setPreparedStatementValue(preparedStatement, i, "string", (String)peopleData.get(i));
  411. }
  412. }
  413. preparedStatement.executeUpdate();
  414. } catch (SQLException e) {
  415. e.printStackTrace();
  416. }
  417. }
  418.  
  419. public static void savePlacesToSQL(List<Object> placesInfo) {
  420. //0: UUID, 1: url, 2: publish_time
  421. List<Object> placesData = nullFixRow(placesInfo);
  422. try (preparedStatement = connection.prepareStatement("INSERT INTO dbo.Places VALUES (?, ?, ?)");){
  423. for (int i = 0; i < 3 ; i++) {
  424. setPreparedStatementValue(preparedStatement, i, "string", (String)placesData.get(i));
  425. }
  426. }
  427. preparedStatement.executeUpdate();
  428. } catch (SQLException e) {
  429. e.printStackTrace();
  430. }
  431. }
  432.  
  433. public static void saveLinksToSQL(List<Object> linksInfo) {
  434. List<Object> linksData = nullFixRow(linksInfo);
  435. try (preparedStatement = connection.prepareStatement("INSERT INTO dbo.Links VALUES (?, ?)");){
  436. for (int i = 0; i < 2 ; i++) {
  437. setPreparedStatementValue(preparedStatement, i, "string", (String)placesData.get(i));
  438. }
  439. }
  440. preparedStatement.executeUpdate();
  441. } catch (SQLException e) {
  442. e.printStackTrace();
  443. }
  444. }
  445.  
  446. public static void saveCategoriesToSQL(List<Object> categoriesInfo) {
  447. List<Object> categoriesData = nullFixRow(categoriesInfo);
  448. try (preparedStatement = connection.prepareStatement("INSERT INTO dbo.Categories VALUES (?, ?)");){
  449. for (int i = 0; i < 2 ; i++) {
  450. setPreparedStatementValue(preparedStatement, i, "string", (String)placesData.get(i));
  451. }
  452. }
  453. preparedStatement.executeUpdate();
  454. } catch (SQLException e) {
  455. e.printStackTrace();
  456. }
  457. }
  458.  
  459. public static void saveTextToSQL(List<Object> textInfo) {
  460. List<Object> textData = nullFixRow(textInfo);
  461. try (preparedStatement = connection.prepareStatement("INSERT INTO dbo.Text VALUES (?, ?)");){
  462. for (int i = 0; i < 2 ; i++) {
  463. setPreparedStatementValue(preparedStatement, i, "string", (String)placesData.get(i));
  464. }
  465. }
  466. preparedStatement.executeUpdate();
  467. } catch (SQLException e) {
  468. e.printStackTrace();
  469. }
  470. }
  471.  
  472. public static void saveSocialToSQL(List<Object> facebookInfo) {
  473. List<Object> socialData = nullFixRow(linksInfo);
  474. try (preparedStatement = connection.prepareStatement("INSERT INTO dbo.Links VALUES (?, ?, ?, ?)");){
  475. for (int i = 0; i < 8 ; i++) {
  476. if (i < 1) {
  477. setPreparedStatementValue(preparedStatement, i, "string", (String)socialData.get(i));
  478. }
  479. else {
  480. setPreparedStatementValue(preparedStatement, i, "int", (int)socialData.get(i));
  481. }
  482. }
  483. }
  484. preparedStatement.executeUpdate();
  485. } catch (SQLException e) {
  486. e.printStackTrace();
  487. }
  488. }
  489.  
  490. public static void saveFacebookToSQL(List<Object> facebookInfo) {
  491. List<Object> facebookData = nullFixRow(linksInfo);
  492. try (preparedStatement = connection.prepareStatement("INSERT INTO dbo.Links VALUES (?, ?, ?, ?)");){
  493. for (int i = 0; i < 4 ; i++) {
  494. if (i < 1) {
  495. setPreparedStatementValue(preparedStatement, i, "string", (String)socialData.get(i));
  496. }
  497. else{
  498. setPreparedStatementValue(preparedStatement, i, "int", (int)socialData.get(i));
  499. }
  500. }
  501. }
  502. preparedStatement.executeUpdate();
  503. } catch (SQLException e) {
  504. e.printStackTrace();
  505. }
  506. }
  507.  
  508.  
  509. //Saves data to SQL
  510. public static void saveDataToSQL(List<List<Object>> cellsAll) throws Exception{
  511. for(int i=0; i<cellsAll.size(); i++){
  512. List<Object> cells = cellsAll.get(i);
  513. String uuid = (String) cells.get(0);
  514. String dateText = (String)cells.get(1);
  515. dateText = dateText.substring(0,dateText.lastIndexOf(":")) + dateText.substring(dateText.lastIndexOf(":")+1);
  516. DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
  517. System.out.println("Date correctly formatted");
  518. Date date = dateFormat.parse(dateText);
  519. long time = (long) date.getTime();
  520. BigInteger bi = BigInteger.valueOf(time);
  521. List<String> keywords = (List<String>) cells.get(6);
  522. //get timestamp
  523. //INSERT INTO dbo.ARTICLES values('9', 'b4093de9e2770b045448cf7e97ee1b67629e4770', '1486284087405', cnn.com, 81, 0.014, NULL, NULL, 31, NULL)
  524. String query = "INSERT INTO dbo.ARTICLES" +
  525. " values('"+
  526. uuid+"', "
  527. + bi + ", " +
  528. "'"+cells.get(2)+"' , " +
  529. "NULL" + ", " +
  530. cells.get(3)+", " +
  531. cells.get(4)+", " +
  532. "NULL" + ", " +
  533. "NULL"/*keywords.toString()*/ + ", " +
  534. keywords.size() + ", " +
  535. "NULL" + ")";
  536. try (Statement stmt = con.createStatement()) {
  537. stmt.executeUpdate(query);
  538. }catch(Exception exe){
  539. continue;
  540. }
  541. for(int j=0; j<keywords.size(); j++){
  542. String hash = keywords.get(j).length() < 4 ? "" + (int)(Math.random()*1000) + 1000 : keywords.get(j).substring(0,4);
  543. hash = hash + uuid;
  544. String query2 = "INSERT INTO dbo.LOOKUP" +
  545. " values('"+hash+"', " +
  546. "'"+uuid+"', " +
  547. time+ ", " +
  548. "'" + keywords.get(j) + "')";
  549. try (Statement stmt = con.createStatement()) {
  550. stmt.executeUpdate(query2);
  551. }catch(Exception exe){
  552. continue;
  553. }
  554. }
  555. }
  556. /*boolean drop=checkSQLForGene();
  557. String geneName=gene.toUpperCase().replaceAll("-", "");
  558. if(drop){
  559. String dropStatement = "DROP TABLE Genes.dbo."+ geneName;
  560. try (Statement stmt = con.createStatement()) {
  561. stmt.executeUpdate(dropStatement);
  562. }catch(SQLException exe){
  563. throw exe;
  564. }
  565. }*/
  566. /*String geneName = "";
  567. String cols =
  568. "CREATE TABLE dbo." +
  569. geneName +
  570. " ("+"UID INT NOT NULL, " +
  571. "TS nvarchar(MAX), " +
  572. "DOM_RANK nvarchar(MAX), " +
  573. "SPAM_SCORE nvarchar(150), " +
  574. "TEXT nvarchar(MAX), " +
  575. "COG_RESULTS nvarchar(MAX), " +
  576. "MISC nvarchar(MAX), " +
  577. "PRIMARY KEY (UID))";
  578. try (Statement stmt = con.createStatement()) {
  579. stmt.executeUpdate(cols);
  580.  
  581. stmt.executeUpdate(cols);
  582. String paraProt=pFasta2;
  583. String paraNucleo=nFasta2;
  584. String homoProt=pFasta;
  585. String homoNucleo=nFasta;
  586. if(paraProt==null)
  587. paraProt="NULL";
  588. else
  589. paraProt="'"+paraProt+"'";
  590. if(paraNucleo==null)
  591. paraNucleo="NULL";
  592. else
  593. paraNucleo="'"+paraNucleo+"'";
  594. if(homoProt==null)
  595. homoNucleo="NULL";
  596. else
  597. homoNucleo="'"+homoNucleo+"'";
  598. if(homoProt==null)
  599. homoProt="NULL";
  600. else
  601. homoProt="'"+homoProt+"'";
  602. int maxRows=numClinicalSNPs;
  603. if(numClinicalSNPs<8)
  604. maxRows=8;
  605. for(int i=0; i<maxRows;i++){
  606. String s;
  607. String geneProp=null;
  608. if(i<8)
  609. geneProp=geneProperties[i+1];
  610. if(geneProp==null)
  611. geneProp="";
  612. String SNP, SNPPheno, SNPMult, SNPURL;
  613. try{
  614. SNP=aFasta.substring(tempSNPs[i].getProtLoc()-1,
  615. tempSNPs[i].getProtLoc())+tempSNPs[i].getProtLoc()+
  616. tempSNPs[i].getProtChange();
  617. SNPPheno=tempSNPs[i].getPhenotype();
  618. SNPPheno=SNPPheno.replace("'", "''");
  619. if(tempSNPs[i].getMultipleConfirmed())
  620. SNPMult="Multiple Publications";
  621. else
  622. SNPMult="Single Publication";
  623. SNPURL=tempSNPs[i].getInfoUrl();
  624. SNPURL=SNPURL.replace("'", "''");
  625. }catch(Exception exe){
  626. SNP=null;
  627. SNPPheno=null;
  628. SNPURL=null; s = "INSERT INTO dbo." +
  629. geneName+
  630. " values('"+i+"', '"+gene1.getProtFasta()+"', " +
  631. "'"+gene1.getFasta()+"', " +
  632. "'"+geneProp+"', " +
  633. paraProt+", " +
  634. paraNucleo+", " +
  635. homoProt+", " +
  636. homoNucleo + ", " +
  637. SNP + ", " +
  638. SNPPheno + ", " +
  639. SNPMult + ", " +
  640. SNPURL+")";
  641. SNPMult=null;
  642. }
  643. if(SNP!=null)
  644. SNP="'"+SNP+"'";
  645. if(SNPPheno!=null)
  646. SNPPheno="'"+SNPPheno+"'";
  647. if(SNP!=null)
  648. SNPMult="'"+SNPMult+"'";
  649. if(SNPURL!=null)
  650. SNPURL="'"+SNPURL+"'";
  651. if(i==0)
  652.  
  653. else if(i<9)
  654. s = "INSERT INTO dbo." +
  655. geneName +
  656. " values('"+i+"', NULL, " +
  657. "NULL, " +
  658. "'"+geneProp+"', " +
  659. "NULL, " +
  660. "NULL, " +
  661. "NULL, " +
  662. "NULL," +
  663. SNP + ", " +
  664. SNPPheno + ", " +
  665. SNPMult + ", " +
  666. SNPURL+")";
  667. else
  668. s = "INSERT INTO dbo." +
  669. geneName +
  670. " values('"+i+"', NULL, " +
  671. "NULL, " +
  672. "NULL, " +
  673. "NULL, " +
  674. "NULL, " +
  675. "NULL, " +
  676. "NULL," +
  677. SNP + ", " +
  678. SNPPheno + ", " +
  679. SNPMult + ", " +
  680. SNPURL+")";
  681. stmt.executeUpdate(s);
  682. }
  683. } catch (Exception exe) {
  684. System.out.println("Gene write error "+gene);
  685. exe.printStackTrace();
  686. throw exe;
  687. }*/
  688. }
  689.  
  690. //Closes SQL connection
  691. private static void closeSQL() throws SQLException{
  692. if(con!=null)
  693. con.close();
  694. }
  695.  
  696. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement