vendredi 13 février 2015

importing packages and design pattern DAO

I am really trying to learn correct ways to access databases that practice security and readable design principles.


First I am having a weird issues importing the packages I need. Below is my App class that I am just trying to run at the moment to make sure everything works and I can connect to a database before I code at further.



package application;

import dataBase.MySQLDataBaseDAO;
import establishConnection; //error

public class App {

public static void main(String[] args) {

MySQLDataBaseDAO database;
new DataBaseConnection();//naturally error a too
}

}


Here are just a snippet of the packages I am attempting to import.



package dataBase;

import java.util.List;

public class MySQLDataBaseDAO {


MySQLDataBaseDAO(){

}

void insert(Person person) {

}

void find(Person person) {

}


This class will create a GUI using dependency injection and ask the user for the username and password and connect to the database.



package establishConnection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

class DataBaseConnection {

private Connection conn = null;
private String URL = "jdbc:mysql://localhost/employee";
private String userName = "";
private String passWord = "";

DataBaseConnection() {
connect();
}


If I was not clear my questions are: 1) How is my import wrong? I want to call the constructor from a class that is in a different package. 2) How does my design look. I did not post the whole code because I did not wnat to annoy anyone with a long post.


Aucun commentaire:

Enregistrer un commentaire