Revision: 66568
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 25, 2014 06:11 by supupoff
Initial Code
//package ur_pack; /** * * auth : Ila Idias * fb.com/idiasila * */ import java.sql.*; public class OuvrConnection { private String driver = "com.mysql.jdbc.Driver"; // pour Mysql (Wampserver ..etc) /***************************************************************************/ // private String driver = "sun.jdbc.odbc.JdbcOdbcDriver"; // pour access // private String driver = "org.postgresql.Driver"; // pour postgresql // private String driver = "oracle.jdbc.driver.OracleDriver"; // pour Oracle /***************************************************************************/ private String url = "jdbc:mysql://localhost/gcn"; //Pour MySql ( gcn is the name of my database ) /***************************************************************************/ // private String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=myDB.mdb;"; //Pour access // private String url = "jdbc:postgresql://localhost/gcn"; //Pour postgresql // private String url = "jdbc:oracle:thin:@localhost:1521:gcn"; //Pour Oracle /***************************************************************************/ private String dbUserId = "root"; private String dbPassword = ""; // ******************************************************** For Select Requests *************************** public ResultSet ReqSelect (String My_Sql) { try{ Class.forName(driver).newInstance(); // instance my driver to connect Connection cn=DriverManager.getConnection(url,dbUserId,dbPassword); // get connect to my database PreparedStatement pr; pr = cn.prepareStatement(My_Sql); ResultSet rs; rs = pr.executeQuery(); return rs; }catch(Exception e){ e.printStackTrace(); return null; } } // ******************************************************** For Update & Insert into & Delete Requests **** public String ReqUID (String My_Sql){ try{ Class.forName(driver).newInstance(); // instance my driver to connect Connection cn=DriverManager.getConnection(url,dbUserId,dbPassword); // get connect to my database PreparedStatement pr; pr = cn.prepareStatement(My_Sql); int r; r = pr.executeUpdate(My_Sql); return +r+ "_Done_"; }catch(Exception e){ e.printStackTrace(); return null; } } }
Initial URL
Initial Description
use This Class to conenct to any database mysql oracle access and postgresql and use functions to select update insert or update data from database --
Initial Title
Advanced Java mysql,oracle,... connect, full functions
Initial Tags
mysql, java, Oracle
Initial Language
Java