数据库操作
// 查询 select name,age,id from tb_emp where sex=”女” order by age;
// 插入 insert into tb_emp values(2,”lily”,”女”,”销售部”);
// 更新 update tb_emp set age=24 where id=2;
// 删除delete from tb_emp where id=1024;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Conn {
Connection con;
public Connection getConnection() {
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
System.out.println("数据加载成功");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
con = DriverManager.getConnection("jdbc:jtds:"+ "sqlserver://localhost:1433/db_jdbc"
, "sa","");
System.out.println("数据库连接成功");
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
public static void main(String[] args) {
Conn c = new Conn();
c.getConnection();
}
}