I want to create a static method in Java to abstract connecting to an SQLite database
Here is my code for the Connect Class:
public class Connect {
public static Connection Connect(String connection, Boolean create) throws ClassNotFoundException, SQLException, FileNotFoundException {
Connection conn = null;
try {
Class.forName("org.sqlite.JDBC");
if(create == false){
try {
FileInputStream f = new FileInputStream(connection);
conn = DriverManager.getConnection("jdbc:sqlite:"+connection);
} catch(Exception NoDB) {
throw NoDB;
}
} else {
conn = DriverManager.getConnection("jdbc:sqlite:"+connection);
}
return conn;
} catch(Exception e){
if(conn != null){
conn.close();
}
throw e;
}
}
}
I want to be able to call the Connect Class like this
Connection conn = Connect();
I am using Intellij and the IDE Keeps suggesting this code to
(Connection) conn = new Connect();
I made the methods static and I am importing the Class. What am I doing wrong how to make the code work that way. I am return a type connection from the static method.