Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 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.  
  7. package javaapplication27;
  8.  
  9.  
  10. import java.io.File;
  11. import java.sql.*;
  12. import java.util.Iterator;
  13. import java.util.List;
  14. import java.util.logging.Level;
  15. import java.util.logging.Logger;
  16. import static javaapplication27.GeodataTxtParser.id;
  17.  
  18. /**
  19.  *
  20.  * @author Пилюгина
  21.  */
  22.  
  23. public class Base {
  24.     public static void main( String args[] ) throws ClassNotFoundException, SQLException
  25.   {
  26.    
  27.   Connection c = null;
  28.     Statement stmt = null;
  29. double x, y, z;
  30.           try {
  31.       Class.forName("org.sqlite.JDBC");
  32.       c = DriverManager.getConnection("jdbc:sqlite:sample2307.db");
  33.       c.setAutoCommit(false);
  34.       System.out.println("Opened database successfully");
  35.  
  36.       stmt = c.createStatement();
  37.  GeodataTxtParser parser = new GeodataTxtParser(new File("kolcovo.txt"));
  38.  
  39.    
  40. List<String[]> strings = parser.parse(); //получаем коллекцию из парсера
  41.       for (String[] geodata : strings) {
  42.           x = Double.valueOf( geodata[1]);
  43.          
  44.           y = Double.valueOf(geodata[2]);
  45.          
  46.           z = Double.valueOf( geodata[3]);
  47.          
  48.          
  49.          
  50.          
  51.          
  52.           PreparedStatement pstmt = c.prepareStatement("INSERT INTO SAMPLE2307 (ID,DATASET,X,Y,Z, POINT) " +"VALUES (?, 4, ?, ?, ?, 4)");
  53.          
  54.           pstmt.setDouble(1, id);
  55.           pstmt.setDouble(2, x);
  56.           pstmt.setDouble(3, y);
  57.           pstmt.setDouble(4, z);
  58.           pstmt.executeUpdate();
  59.           id++; }
  60.     } catch ( Exception e ) {
  61.       System.err.println( e.getClass().getName() + ": " + e.getMessage() );
  62.       System.exit(0);
  63.     }
  64.      
  65.  
  66.  
  67.         try {
  68.             stmt.close();
  69.             c.commit();
  70.       c.close();
  71.         } catch (SQLException ex) {
  72.             Logger.getLogger(GeodataTxtParser.class.getName()).log(Level.SEVERE, null, ex);
  73.         }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement