1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| package com.javatpoint.models;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.sql.*;
import com.javatpoint.models.Emp;
public class JdbcModel { // extends HttpServlet { // in the future
// Jdbc connection parameters
private static final Integer port=3306;
private String server;
private String db;
private String login;
private String password;
public JdbcModel(String server, String db, String login, String password) {
super();
// this.port = port;
this.server = server;
this.db = db;
this.login = login;
this.password = password;
}
public int getPort() { // to demonstrate a very simple junit test
return (int) port;
}
private Connection connection;
// procedure that connect to the DB
public void connect() throws SQLException
{
String url="jdbc:mysql://"+server+":"+port+"/"+db; // the database address
connection = DriverManager.getConnection(url, login, password);
}
// procedure that perform a stmt.executeQuery search for a particular name but w/o presentation work
// which is bad practice
public List<Emp> searchEmpTBC(String empname) throws SQLException
{..}
} // end class
Merci d'avance |
Partager