Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample;
- import javafx.application.Application;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- import java.sql.*;
- public class Main extends Application {
- @Override
- public void start(Stage primaryStage) throws Exception{
- Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
- primaryStage.initStyle(StageStyle.UNDECORATED);
- primaryStage.setTitle("Hello World");
- primaryStage.setScene(new Scene(root));
- primaryStage.show();
- }
- public static void createNewDatabase(String fileName) {
- String url = "jdbc:sqlite:C:/Users/danie/" + fileName;
- try (Connection conn = DriverManager.getConnection(url)) {
- if (conn != null) {
- DatabaseMetaData meta = conn.getMetaData();
- System.out.println("The driver name is " + meta.getDriverName());
- System.out.println("A new database has been created.");
- }
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- }
- public static void connect() {
- Connection conn = null;
- try {
- // db parameters
- String url = "jdbc:sqlite:C:/Users/danie/test.db";
- // create a connection to the database
- conn = DriverManager.getConnection(url);
- System.out.println("Connection to SQLite has been established.");
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- } finally {
- try {
- if (conn != null) {
- Statement statement = conn.createStatement();
- ResultSet rs = statement.executeQuery("select * from person");while(rs.next())
- {
- // read the result set
- System.out.println("name = " + rs.getString("name"));
- System.out.println("id = " + rs.getInt("id"));
- }
- conn.close();
- }
- } catch (SQLException ex) {
- System.out.println(ex.getMessage());
- }
- }
- }
- public static void main(String[] args) {
- //launch(args);
- connect();
- //createNewDatabase("test.db");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement