Yurttas/PL/DBL/mssql/F/04/00/01/DBCreate11.java
Jump to navigation
Jump to search
1/**
2 * Copyright(C) 2004
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : January 1, 2004.
11 * @author : Salih Yurttas.
12 */
13
14
15import dbops.DBConnect;
16import dbops.DBTable;
17
18import java.sql.*;
19import java.net.*;
20
21public class DBCreate11 {
22
23 private static String driverClass = "com.mysql.jdbc.Driver",
24 url = "jdbc:mysql:",
25 suffix = "//localhost/bank";
26
27 private static Connection con;
28
29 private static String urlDB = url + suffix + ".";
30
31 public static void main (String[] args) {
32 String username = args[0];
33 String password = args[1];
34
35 DBConnect dbc = new DBConnect();
36
37 try {
38 if(dbc.connect(args[0], args[1])) {
39 System.out.println("Connected to " + urlDB);
40
41 con = dbc.getConnect();
42
43 DBTable dbCreate = new DBTable(con);
44
45 String createTable = "CREATE TABLE AA(itemA VARCHAR(16) NOT NULL," +
46 "itemB VARCHAR(16) NOT NULL," +
47 "PRIMARY KEY(itemA))";
48
49 if(dbCreate.setStatement(createTable))
50 System.out.println("Table AA is created into " + urlDB);
51 if(dbc.disconnect(con))
52 System.out.println("Disconnected from " + urlDB);
53 }
54 else System.out.println("Could not connect to " + urlDB);
55 }
56 catch(SQLException sqle) {
57 System.err.println("Error accessing " + urlDB);
58 System.err.println(sqle.getMessage());
59 }
60 }
61
62}