Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class CModel extends ObjDraw
- {
- public static void createNewDatabase(String fileName) {
- String url = "jdbc:sqlite:ObjDraw.db";
- 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 createNewTable() {
- String url = "jdbc:sqlite:ObjDraw.db";
- String sql = "CREATE TABLE IF NOT EXISTS Figuren (\n"
- + " id integer autoincrement PRIMARY KEY,\n"
- + " name text NOT NULL,\n"
- + " Farbe text NOT NULL,\n"
- + " X integer NOT NULL,\n"
- + " Y integer NOT NULL,\n"
- + ");";
- try (Connection conn = DriverManager.getConnection(url);
- Statement stmt = conn.createStatement()) {
- // create a new table
- stmt.execute(sql);
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- }
- public CModel( )
- {
- createNewDatabase("ObjDraw.db");
- createNewTable();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement