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 sql;
- import java.sql.Connection;
- import java.sql.DatabaseMetaData;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- /**
- *
- * @author Tu Anh
- */
- public class SQL {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws ClassNotFoundException {
- // TODO code application logic here
- Connection conn = null;
- try{
- String user="sa";
- String pass = "123456";
- String url = "jdbc:sqlserver://localhost:1433;databaseName=bangdiem;";
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- conn = DriverManager.getConnection(url,user,pass);
- if (conn != null) {
- DatabaseMetaData dm = (DatabaseMetaData) conn.getMetaData();
- System.out.println("Driver name: " + dm.getDriverName());
- System.out.println("Driver version: " + dm.getDriverVersion());
- System.out.println("Product name: " + dm.getDatabaseProductName());
- System.out.println("Product version: " + dm.getDatabaseProductVersion());
- }
- Statement stm = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
- ResultSet rs = stm.executeQuery("select * from diemthi");
- rs.beforeFirst();
- while(rs.next()){
- System.out.println(rs.getString("tensinhvien")+" "+ rs.getFloat("diemtoan")+ " "+ rs.getFloat("diemly")+" "+rs.getFloat("diemhoa"));
- }
- rs.close();
- stm.close();
- }
- catch(SQLException ex){
- ex.printStackTrace();
- }finally {
- try {
- if (conn != null && !conn.isClosed()) {
- conn.close();
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement