Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.sql.*;
- public class Connector {
- private static final String url = "jdbc:mysql://localhost:3306/polynom"; //define database
- private static final String user = "root";
- private static final String password = "110895aa";
- protected static int degree;
- protected static int j;
- protected static int poly;
- protected static String type;
- // JDBC variables for opening and managing connection
- protected static Connection con;
- protected static Statement stmt;
- protected static ResultSet rs;
- protected static int connectionTimes=0;
- protected static String polyType;
- protected static int[] arrayOfPolyList = new int[20];
- protected static int arrayOfPolyListSize =0;
- private int i;
- void getConnection(String query){
- i=0;
- try {
- // opening database connection to MySQL server
- con = DriverManager.getConnection(url, user, password);
- // getting Statement object to execute query
- stmt = con.createStatement();
- // executing SELECT query
- rs = stmt.executeQuery(query);
- //Don't do anything while connect at first!
- if (connectionTimes > 0) {
- while(rs.next()) {
- arrayOfPolyList[i] = rs.getInt("poly");
- i++;
- }
- arrayOfPolyListSize =i; //getting size of the array
- }
- } catch (SQLException sqlEx) {
- sqlEx.printStackTrace();
- } finally {
- //close connection ,stmt and resultset here
- try { con.close(); } catch(SQLException se) { /*can't do anything */ }
- try { stmt.close(); } catch(SQLException se) { /*can't do anything */ }
- try { rs.close(); } catch(SQLException se) { /*can't do anything */ }
- }
- connectionTimes++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement