时间:2021-07-01 10:21:17 帮助过:4人阅读
public class Test {
//常量定义(一般用全大写)
public static final String DBDRIVER="net.sourceforge.jtds.jdbc.Driver";
public static final String DBURL
="jdbc:jtds:sqlserver://127.0.0.1:1433;DatabaseName=pengmengyue";//数据库名称
// public static final String DBDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";
// public static final String DBURL="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=testdb";
public static final String USER="sa";
public static final String PASSWORD="123";
public static void main(String[] args) throws Exception {
try
{ Class.forName(DBDRIVER);//加载驱动
Connection cn=DriverManager.getConnection(DBURL,USER,PASSWORD);
Statement st=cn.createStatement();//执行命令
st.executeUpdate("insert into Grade values(‘1011‘,‘123‘,‘98‘)");
cn.close();//关闭连接
}
catch(Exception ex){ex.printStackTrace();}
}
}
连接数据库
标签: