/ Published in: Java
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
--
--
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//package ur_pack; /** * * auth : Ila Idias * fb.com/idiasila * */ import java.sql.*; public class OuvrConnection { /***************************************************************************/ // 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: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 /***************************************************************************/ // ******************************************************** For Select Requests *************************** { try{ Class.forName(driver).newInstance(); // instance my driver to connect pr = cn.prepareStatement(My_Sql); ResultSet rs; rs = pr.executeQuery(); return rs; e.printStackTrace(); return null; } } // ******************************************************** For Update & Insert into & Delete Requests **** try{ Class.forName(driver).newInstance(); // instance my driver to connect pr = cn.prepareStatement(My_Sql); int r; r = pr.executeUpdate(My_Sql); return +r+ "_Done_"; e.printStackTrace(); return null; } } }