package ee.tpu.hk.links; import java.sql.*; /** * Klass andmebaasiühenduse loomiseks. * 2003 Haapsalu Kolledz * @author Berit Hiieväli */ public class db { private String driver = "com.mysql.jdbc.Driver"; private String database = "jdbc:mysql:///minu_lingid"; private String user = ""; private String passwd = ""; public db() { registerDriver(); } public ResultSet executeQuery(String SQLCommand) { ResultSet rs1 = null; try { Connection con = DriverManager.getConnection(database, user, passwd); Statement stmt = con.createStatement(); rs1 = stmt.executeQuery(SQLCommand); con.close(); } catch(Exception e) { System.err.println(e.getMessage()); } return rs1; } public void updateQuery(String SQLCommand) { try { Connection con = DriverManager.getConnection(database, user, passwd); Statement stmt = con.createStatement(); stmt.executeUpdate(SQLCommand); con.close(); } catch(Exception e) { System.err.println(e.getMessage()); } } public void registerDriver() { try { Class.forName(driver).newInstance(); // DriverManager.registerDriver(new JdbcOdbcDriver()); } catch(Exception e) { System.err.println(e.getMessage()); } } public void setDatabaseName(String dbName) { this.database=dbName; } }