Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication27;
- import java.io.File;
- import java.sql.*;
- import java.util.Iterator;
- import java.util.List;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import static javaapplication27.GeodataTxtParser.id;
- /**
- *
- * @author Пилюгина
- */
- public class Base {
- public static void main( String args[] ) throws ClassNotFoundException, SQLException
- {
- Connection c = null;
- Statement stmt = null;
- double x, y, z;
- try {
- Class.forName("org.sqlite.JDBC");
- c = DriverManager.getConnection("jdbc:sqlite:sample2307.db");
- c.setAutoCommit(false);
- System.out.println("Opened database successfully");
- stmt = c.createStatement();
- GeodataTxtParser parser = new GeodataTxtParser(new File("kolcovo.txt"));
- List<String[]> strings = parser.parse(); //получаем коллекцию из парсера
- for (String[] geodata : strings) {
- x = Double.valueOf( geodata[1]);
- y = Double.valueOf(geodata[2]);
- z = Double.valueOf( geodata[3]);
- PreparedStatement pstmt = c.prepareStatement("INSERT INTO SAMPLE2307 (ID,DATASET,X,Y,Z, POINT) " +"VALUES (?, 4, ?, ?, ?, 4)");
- pstmt.setDouble(1, id);
- pstmt.setDouble(2, x);
- pstmt.setDouble(3, y);
- pstmt.setDouble(4, z);
- pstmt.executeUpdate();
- id++; }
- } catch ( Exception e ) {
- System.err.println( e.getClass().getName() + ": " + e.getMessage() );
- System.exit(0);
- }
- try {
- stmt.close();
- c.commit();
- c.close();
- } catch (SQLException ex) {
- Logger.getLogger(GeodataTxtParser.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement