You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.2 KiB
51 lines
1.2 KiB
package Connect;
|
|
|
|
import javax.swing.*;
|
|
import java.sql.*;
|
|
public class Connect {
|
|
private Statement sql=null;
|
|
private ResultSet result;
|
|
// private String url="jdbc:mysql://localhost:3306/userinfo?serverTimezone=GMT%2B8";
|
|
// private String user="root";
|
|
// private String passWord ="1996315211cjr";
|
|
private Connection con=null;
|
|
private static Connect connect=new Connect("jdbc:mysql://localhost:3306/userinfo?serverTimezone=GMT%2B8","root","1996315211cjr");
|
|
// private Connect con=new Connect(url,user,passWord);
|
|
public static Connect getCon(){
|
|
return connect;
|
|
}
|
|
private Connect(String url, String user, String passWord){
|
|
try{
|
|
Class.forName("com.mysql.jdbc.Driver");
|
|
}
|
|
catch(Exception e){
|
|
System.out.print(e);
|
|
}
|
|
try{
|
|
con = DriverManager.getConnection(url,user,passWord);
|
|
}
|
|
catch(SQLException e){
|
|
System.out.println(e);
|
|
}
|
|
}
|
|
public int getUpdate(String str){
|
|
int insert=0;
|
|
try{
|
|
sql=con.createStatement();
|
|
insert=sql.executeUpdate(str);
|
|
}catch(SQLException e){
|
|
System.out.println(e);
|
|
}
|
|
return insert;
|
|
}
|
|
public ResultSet getResult(String str){
|
|
try{
|
|
sql=con.createStatement();
|
|
result=sql.executeQuery(str);
|
|
}catch(SQLException e){
|
|
System.out.println(e);
|
|
}
|
|
return result;
|
|
}
|
|
}
|