Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- thufir@dur:~$
- thufir@dur:~$ java -jar NetBeansProjects/Server/dist/Server.jar
- Jul 05, 2014 7:43:21 PM net.bounceme.dur.db.Query metaData
- INFO: id 4
- Jul 05, 2014 7:43:21 PM net.bounceme.dur.db.Query metaData
- INFO: title 12
- Jul 05, 2014 7:43:21 PM net.bounceme.dur.db.Query metaData
- INFO: phone 4
- Jul 05, 2014 7:43:21 PM net.bounceme.dur.db.Query metaData
- INFO: state_timestamp 93
- Jul 05, 2014 7:43:21 PM net.bounceme.dur.db.Query metaData
- INFO: created 93
- Jul 05, 2014 7:43:21 PM net.bounceme.dur.db.Query metaData
- INFO: state 5
- Jul 05, 2014 7:43:21 PM net.bounceme.dur.db.Query metaData
- INFO: user_id 5
- Jul 05, 2014 7:43:21 PM net.bounceme.dur.server.Driver startServer
- INFO: started server
- ^Cthufir@dur:~$
- thufir@dur:~$
- thufir@dur:~$ mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 83
- Server version: 5.5.37-0ubuntu0.14.04.1 (Ubuntu)
- Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
- Oracle is a registered trademark of Oracle Corporation and/or its
- affiliates. Other names may be trademarks of their respective
- owners.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql>
- mysql> describe titles.titles;
- +-----------------+-------------+------+-----+---------------------+----------------+
- | Field | Type | Null | Key | Default | Extra |
- +-----------------+-------------+------+-----+---------------------+----------------+
- | id | int(11) | NO | PRI | NULL | auto_increment |
- | created | timestamp | NO | | 0000-00-00 00:00:00 | |
- | phone | int(11) | NO | | NULL | |
- | title | varchar(45) | NO | | NULL | |
- | state | smallint(6) | NO | | NULL | |
- | state_timestamp | timestamp | NO | | 0000-00-00 00:00:00 | |
- | user_id | smallint(6) | NO | | NULL | |
- +-----------------+-------------+------+-----+---------------------+----------------+
- 7 rows in set (0.00 sec)
- mysql>
- mysql> quit
- Bye
- thufir@dur:~$
- thufir@dur:~$ cat NetBeansProjects/Server/src/net/bounceme/dur/db/Query.java
- package net.bounceme.dur.db;
- import java.sql.Connection;
- import java.sql.DatabaseMetaData;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import net.bounceme.dur.server.MyProps;
- import net.bounceme.dur.server.RecordsQueueWrapper;
- import net.bounceme.dur.server.Title;
- public class Query {
- private static final Logger log = Logger.getLogger(Query.class.getName());
- private RecordsQueueWrapper recordsQueue = RecordsQueueWrapper.getInstance();
- String driver, url, user, password;
- public Query(MyProps props) {
- driver = props.getDbDriver();
- url = props.getDbUrl();
- user = props.getDbUser();
- password = props.getDbPassword();
- }
- public void rows() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
- Connection connection = connect();
- PreparedStatement statement = connection.prepareStatement("SELECT * FROM Titles.titles");
- ResultSet resultSet = statement.executeQuery();
- }
- public void metaData() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
- Connection c = null;
- c = connect();
- String catalog = null;
- String schemaPattern = null;
- String tableNamePattern = "titles";
- String columnNamePattern = null;
- DatabaseMetaData meta = c.getMetaData();
- ResultSet result = meta.getColumns(catalog, schemaPattern, tableNamePattern, columnNamePattern);
- Map<String, Integer> map = new HashMap<>();
- while (result.next()) {
- map.put(result.getString(4), result.getInt(5));
- }
- for (Map.Entry<String, Integer> entry : map.entrySet()) {
- String key = entry.getKey();
- Integer value = entry.getValue();
- log.log(Level.INFO, "{0}\t{1}", new Object[]{key, value});
- }
- }
- private Connection connect() throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
- log.fine("connecting...");
- Connection connection = null;
- Class.forName(driver).newInstance();
- connection = DriverManager.getConnection(url, user, password);
- log.fine("...connected");
- return connection;
- }
- }
- thufir@dur:~$
- thufir@dur:~$
Advertisement
Add Comment
Please, Sign In to add comment