OmniSciDB  c07336695a
FirstTry Class Reference
+ Collaboration diagram for FirstTry:

Static Public Member Functions

static void main (String[] args)
 

Static Package Attributes

static final Logger logger = LoggerFactory.getLogger(FirstTry.class)
 
static final String JDBC_DRIVER = "com.omnisci.jdbc.OmniSciDriver"
 
static final String DB_URL = "jdbc:omnisci:localhost:6273:omnisci:http"
 
static final String USER = "admin"
 
static final String PASS = "HyperInteractive"
 

Detailed Description

Definition at line 25 of file FirstTry.java.

Member Function Documentation

◆ main()

static void FirstTry.main ( String []  args)
inlinestatic

Definition at line 36 of file FirstTry.java.

References sql(), and Experimental.String.

36  {
37  Connection conn = null;
38  Statement stmt = null;
39  try {
40  // STEP 2: Register JDBC driver
41  Class.forName(JDBC_DRIVER);
42 
43  // STEP 3: Open a connection
44  logger.info("Connecting to database...");
45  conn = DriverManager.getConnection(DB_URL, USER, PASS);
46 
47  String sql;
48 
49  // logger.info("Doing prepared statement");
50  //
51  PreparedStatement ps = null;
52  ResultSet rs = null;
53  // sql = "INSERT INTO alltypes (b1, s1, i1, b2, f1, d1, c1, v1, t1, t2, t3, d2)
54  // VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; ps =
55  // conn.prepareStatement(sql);
56  //
57  // ps.setBoolean(1, true);
58  // ps.setShort(2, (short)1);
59  // ps.setInt(3, 20);
60  // ps.setInt(4, 400);
61  // ps.setFloat(5, (float)4000.04);
62  // ps.setBigDecimal(6, new BigDecimal(12.2));
63  // ps.setString(7, "String1");
64  // ps.setString(8, "String2");
65  // ps.setString(9, "String3");
66  // ps.setTime(10, new Time(0));
67  // ps.setTimestamp(11, new Timestamp(0));
68  // ps.setDate(12, new Date(0));
69  //
70 
71  // ResultSet rs = ps.executeQuery();
72 
73  // STEP 4: Execute a query
74  logger.info("Creating statement...");
75  stmt = conn.createStatement();
76 
77  sql = "SELECT uniquecarrier from flights_2008_7M limit 5";
78  rs = stmt.executeQuery(sql);
79 
80  // STEP 5: Extract data from result set
81  while (rs.next()) {
82  // Retrieve by column name
83  // int id = rs.getInt("id");
84  // int age = rs.getInt("age");
85  String uniquecarrier = rs.getString("uniquecarrier");
86  // String last = rs.getString("last");
87 
88  // Display values
89  logger.info("uniquecarrier: " + uniquecarrier);
90  // logger.info(", Age: " + age);
91  // logger.info(", First: " + first);
92  // logger.info(", Last: " + last);
93  }
94  logger.info("Doing prepared statement");
95 
96  ps = null;
97  sql = "SELECT uniquecarrier from flights limit 5";
98  ps = conn.prepareStatement(sql);
99 
100  rs = ps.executeQuery();
101 
102  // STEP 5: Extract data from result set
103  while (rs.next()) {
104  // Retrieve by column name
105  // int id = rs.getInt("id");
106  // int age = rs.getInt("age");
107  String uniquecarrier = rs.getString("uniquecarrier");
108  // String last = rs.getString("last");
109 
110  // Display values
111  logger.info("PS uniquecarrier: " + uniquecarrier);
112  // logger.info(", Age: " + age);
113  // logger.info(", First: " + first);
114  // logger.info(", Last: " + last);
115  }
116 
117  DatabaseMetaData dbmeta = conn.getMetaData();
118 
119  rs = dbmeta.getSchemas();
120  while (rs.next()) {
121  String schema = rs.getString("TABLE_SCHEM");
122  logger.info("TABLE_SCHEM: " + schema);
123  }
124 
125  rs = dbmeta.getTableTypes();
126  while (rs.next()) {
127  String schema = rs.getString(1);
128  logger.info("TYPE: " + schema);
129  }
130 
131  // STEP 6: Clean-up environment
132  rs.close();
133  stmt.close();
134  conn.close();
135  } catch (SQLException se) {
136  // Handle errors for JDBC
137  se.printStackTrace();
138  } catch (Exception e) {
139  // Handle errors for Class.forName
140  e.printStackTrace();
141  } finally {
142  // finally block used to close resources
143  try {
144  if (stmt != null) {
145  stmt.close();
146  }
147  } catch (SQLException se2) {
148  } // nothing we can do
149  try {
150  if (conn != null) {
151  conn.close();
152  }
153  } catch (SQLException se) {
154  se.printStackTrace();
155  } // end finally try
156  } // end try
157  logger.info("Goodbye!");
158  } // end main
static final String JDBC_DRIVER
Definition: FirstTry.java:29
auto sql(const std::string &sql_stmts)
static final String USER
Definition: FirstTry.java:33
static final String DB_URL
Definition: FirstTry.java:30
static final String PASS
Definition: FirstTry.java:34
+ Here is the call graph for this function:

Member Data Documentation

◆ DB_URL

final String FirstTry.DB_URL = "jdbc:omnisci:localhost:6273:omnisci:http"
staticpackage

Definition at line 30 of file FirstTry.java.

◆ JDBC_DRIVER

final String FirstTry.JDBC_DRIVER = "com.omnisci.jdbc.OmniSciDriver"
staticpackage

Definition at line 29 of file FirstTry.java.

◆ logger

final Logger FirstTry.logger = LoggerFactory.getLogger(FirstTry.class)
staticpackage

Definition at line 26 of file FirstTry.java.

◆ PASS

final String FirstTry.PASS = "HyperInteractive"
staticpackage

Definition at line 34 of file FirstTry.java.

◆ USER

final String FirstTry.USER = "admin"
staticpackage

Definition at line 33 of file FirstTry.java.


The documentation for this class was generated from the following file: