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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
package hall;
import java.io.*;
import java.sql.*;
public class Connect implements java.io.Serializable{
private String driver="com.mysql.jdbc.Driver";
private String server="jdbc:mysql://localhost/mabase";
private String user="root";
private String passwd="123123";
private Connection conn = null;
private ResultSet rs = null;
public Connect(){}
void setDriver(String d){
this.driver=d;
}
public String getDriver(){
return this.driver;
}
public void setServer(String d){
this.server=d;
}
public String getServer(){
return this.server;
}
public void setUser(String d){
this.user=d;
}
public String getUser(){
return this.user;
}
public void setPasswd(String d){
this.passwd=d;
}
public String getPasswd(){
return this.passwd;
}
public void connect(){
try
{
Class.forName(driver);
}
catch(ClassNotFoundException Exception)
{
System.out.println("error occoured during loading the driver ");
}
try
{
conn = DriverManager.getConnection(server,user,passwd);
}
catch(Exception exception1)
{
System.out.println(exception1.toString());
}
}
public Connection getConn(){
return conn;
}
public ResultSet getRs(String req) throws Exception{
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(req);
return rs;
}
public void updateReq (String req) throws Exception
{
Statement stmt = conn.createStatement();
stmt.executeUpdate(req);
}
public PreparedStatement getPrepSt(String req) throws Exception{
PreparedStatement prep = conn.prepareStatement(req);
return prep;
}
} |
Partager