链接Oracle数据库
package Com.Cqvie;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class Test {
//常量定义(一般用全大写)localhost
public static final String DBDRIVER="net.sourceforge.jtds.jdbc.Driver";
public static final String DBURL="jdbc:jtds:sqlserver://127.0.0.1 (本机访问) :1433;DatabaseName=Wangchengyan"; // 学校默认端口
public static final String USER="Wang";
public static final String PASSWORD="123";
public static void main(String[] args) throws Exception {
try
{
Class.forName(DBDRIVER);//加载驱动 (字母大写是常量,值不变)
Connection cn=DriverManager.getConnection(DBURL);//连接
Statement st=cn.createStatement();//执行命令
st.executeUpdate("insert into Student values('1123','莉莉','女','1996-11-06','软件')");
cn.close();
}
catch(Exception ex){ex.printStackTrace();}
}
}