Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package library;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.sql.Date;
- public class DataBaseExporter {
- private ResultSet result = null;
- private Statement statement = null;
- private Connection connection = null;
- public void close() throws SQLException {
- if (!result.equals(null))
- result.close();
- if (!statement.equals(null))
- statement.close();
- if (!connection.equals(null))
- connection.close();
- }
- public void executeQuery(String arg0) throws SQLException, ClassNotFoundException {
- if (arg0.isEmpty())
- return;
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/library", "root", "123456");
- statement = connection.createStatement();
- result = statement.executeQuery(arg0);
- }
- public boolean hasNext() throws SQLException {
- if (!result.equals(null))
- return result.next();
- return false;
- }
- public String getAuthor() throws SQLException {
- if (!result.equals(null))
- return result.getString("author");
- return null;
- }
- public String getFormat() throws SQLException {
- if (!result.equals(null))
- return result.getString("format");
- return null;
- }
- public String[] getKeywordsArray() throws SQLException {
- if (result.equals(null))
- return null;
- String[] keywords = result.getString("keywords").split(",");
- if (keywords.length < 0) {
- return null;
- }
- return keywords;
- }
- public String getKeywords() throws SQLException {
- if (!result.equals(null))
- return result.getString("keywords");
- return null;
- }
- public String getPublisher() throws SQLException {
- if (!result.equals(null))
- return result.getString("publisher");
- return "";
- }
- public float getPrice() throws SQLException {
- if (!result.equals(null))
- return result.getFloat("price");
- return 0.0f;
- }
- public String getTitle() throws SQLException {
- if (!result.equals(null))
- return result.getString("title");
- return null;
- }
- public int getID() throws SQLException {
- int id = 0;
- if (!result.equals(null))
- id = result.getInt("id");
- if (id < 0)
- return 0;
- return id;
- }
- public Date getDate() throws SQLException {
- Date date = null;
- if (!result.equals(null)) {
- date = result.getDate("date");
- return date;
- }
- return date;
- }
- public String getISBN() throws SQLException {
- if (!result.equals(null))
- return result.getString("ISBN");
- return null;
- }
- public String getName() throws SQLException {
- return result.getString("name");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement