Advertisement
Guest User

cancercancer

a guest
May 30th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class CModel extends ObjDraw
  4. {
  5. public static void createNewDatabase(String fileName) {
  6.  
  7. String url = "jdbc:sqlite:ObjDraw.db";
  8.  
  9. try (Connection conn = DriverManager.getConnection(url)) {
  10. if (conn != null) {
  11. DatabaseMetaData meta = conn.getMetaData();
  12. System.out.println("The driver name is " + meta.getDriverName());
  13. System.out.println("A new database has been created.");
  14. }
  15.  
  16. } catch (SQLException e) {
  17. System.out.println(e.getMessage());
  18. }
  19. }
  20. public static void createNewTable() {
  21.  
  22. String url = "jdbc:sqlite:ObjDraw.db";
  23.  
  24.  
  25. String sql = "CREATE TABLE IF NOT EXISTS Figuren (\n"
  26. + " id integer autoincrement PRIMARY KEY,\n"
  27. + " name text NOT NULL,\n"
  28. + " Farbe text NOT NULL,\n"
  29. + " X integer NOT NULL,\n"
  30. + " Y integer NOT NULL,\n"
  31. + ");";
  32.  
  33. try (Connection conn = DriverManager.getConnection(url);
  34. Statement stmt = conn.createStatement()) {
  35. // create a new table
  36. stmt.execute(sql);
  37. } catch (SQLException e) {
  38. System.out.println(e.getMessage());
  39. }
  40. }
  41. public CModel( )
  42. {
  43. createNewDatabase("ObjDraw.db");
  44. createNewTable();
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement