Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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.
- */
- package MySQL;
- import DeII.Cau2.*;
- import java.sql.*;
- /**
- *
- * @author Luong
- */
- public class SuperKetNoiCSDL {
- String ckn="";
- Connection conn;
- Statement stmMain;
- public SuperKetNoiCSDL() {
- }
- public void KetNoiMySQL(String dbName)
- {
- try
- {
- ckn="jdbc:mysql://demo.net/"+dbName;
- conn = DriverManager.getConnection(ckn, "root", "");
- stmMain = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
- System.out.print("Kết nối thành công!\n");
- }
- catch(Exception e)
- {
- System.out.print("Kết nối thất bại!\n");
- }
- }
- public ResultSet LayDL(String tableName)
- {
- try
- {
- ResultSet rs;
- String qr = "Select * From "+tableName;
- rs = stmMain.executeQuery(qr);
- return rs;
- }
- catch(Exception e)
- {
- System.out.print("Lấy dữ liệu thất bại!\n");
- return null;
- }
- }
- public ResultSet LayDL(String tableName, String dk)
- {
- try
- {
- ResultSet rs;
- String qr = "Select * From "+tableName+" Where "+dk;
- rs = stmMain.executeQuery(qr);
- return rs;
- }
- catch(Exception e)
- {
- System.out.print("Lấy dữ liệu thất bại!\n");
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement