找本书看看吧。JDBC方面的,
下面是一个查询的例子。更新也是调用Statement的一个方法。
[CODE]
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestTest{
public static void main(String[] args){
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;databasename=pubs","sa","sa");
Statement stm=con.createStatement();
ResultSet rs=stm.executeQuery("select * from jobs");
while(rs.next()){
System.out.println(rs.getString("job_id"));
}
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
[/CODE]