我的eclipse连接sqlserver2008没有反应?包已经正确导入 15
publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubConnectionconn=null;...
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection conn = null;
Statement stmt = null;
String GradeName = "yy";
//1.加载驱动
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
// TODO: handle exception
}
//2.建立连接
try {
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=MySchool","","");
System.out.println("建立连接成功");
stmt = conn.createStatement();
StringBuffer sbSql = new StringBuffer("insert into Grade values('");
sbSql.append(GradeName + "'");
stmt.execute(sbSql.toString());
} catch (Exception e) {
// TODO: handle exception
}finally{
try {
if (null != stmt) {
stmt.close();
System.out.println("关闭Statement");
}if (null != conn) {
conn.close();
System.out.println("关闭连接");
}
} catch (Exception e2) {
// TODO: handle exception
}
}
} 展开
// TODO Auto-generated method stub
Connection conn = null;
Statement stmt = null;
String GradeName = "yy";
//1.加载驱动
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
// TODO: handle exception
}
//2.建立连接
try {
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=MySchool","","");
System.out.println("建立连接成功");
stmt = conn.createStatement();
StringBuffer sbSql = new StringBuffer("insert into Grade values('");
sbSql.append(GradeName + "'");
stmt.execute(sbSql.toString());
} catch (Exception e) {
// TODO: handle exception
}finally{
try {
if (null != stmt) {
stmt.close();
System.out.println("关闭Statement");
}if (null != conn) {
conn.close();
System.out.println("关闭连接");
}
} catch (Exception e2) {
// TODO: handle exception
}
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询