package com.pub.datamanage;
import java.sql.*;
public class DataLink
{
public Connection conn = null;
public DataLink()
{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=course";
String user="course";
String password="course";
this.conn = DriverManager.getConnection(url,user,password);
conn.setAutoCommit(false);
}catch (Exception e)
{
System.out.println("error: " + e.getMessage());
}
}
public Connection getConnection()
{
return this.conn;
}
public static void main(String args[])throws SQLException
{
DataLink dlink = new DataLink();
try{
Connection con = dlink.getConnection();
Statement stmt = con.createStatement();
ResultSet rset = stmt.executeQuery("select * from CourseKind");
while (rset.next ())
{
System.out.println (rset.getString(1)+" " + rset.getString(2));
}
rset.close();
stmt.close();
}catch(Exception e){
System.out.println("error"+ e.toString());
}
}
}
为什么运行的时候没有什么反应的。
他应该有输出才对啊。