import java.sql.*;
public class db
{
public static void main(String [] args)
{
try
{
// 串連SQL Server 2005的執行個體代碼
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
String url="jdbc:sqlserver://localhost:1433;DatabaseName=demo";
//pubs為你的資料庫的
String user="sa";
String password="zxm10";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from T_User";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
System.out.println("the first field is : " + rs.getString(1));
System.out.println("the second field is : " + rs.getString(2));
}
rs.close();
stmt.close();
conn.close();
/* 串連SQL Server 2000的執行個體代碼
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs為你的資料庫的
String user="sa";
String password="hxh";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from jobs";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
System.out.println("the first field is : " + rs.getString(1) + "<br>");
System.out.println("the second field is : " + rs.getString(2) + "<br>");
}
rs.close();
stmt.close();
conn.close(); */
System.out.println("asdfas");
}
catch (Exception ex)
{
System.out.print("error. " + ex.getMessage());
}
}
}