Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DB;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author nilsf
- */
- public class DataBase {
- static Connection con;
- public static Connection getCon()
- {
- try {
- if(con==null){
- Class.forName("com.mysql.jdbc.Driver");
- con=DriverManager.getConnection("jdbc:mysql://localhost:3306/prog","root","bjerk7412395");
- }
- }catch (ClassNotFoundException ex) {
- Logger.getLogger(DataBase.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(DataBase.class.getName()).log(Level.SEVERE, null, ex);
- }
- return con;
- }
- public static void CloseConnection()
- {
- if(con!=null)
- {
- try
- {
- con.close();
- con = null;
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
- }
- public static ResultSet getResultFromSqlQuery(String SqlQueryString)
- {
- System.out.println("in funcation");
- ResultSet rs=null;
- if(con==null)
- {
- getCon();
- }
- try
- {
- rs = con.createStatement().executeQuery(SqlQueryString);
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return rs;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement