- 论坛徽章:
- 0
|
请说具体点儿啊!!!下面的程序用java解释器解释运行可以出正确结果阿!
import java.sql.*;
class Testj{
public static void main(String args[])
{ String RL = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
String user ="sa";
String password = "";
String sqlStr = "select * from jobs";
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println( "类实例化成功!" );
System.out.println("slkdjf");
Connection con = DriverManager.getConnection(RL,user,password);
System.out.println( "创建连接对像成功!" );
Statement st = con.createStatement();
System.out.println( "创建Statement成功!" );
ResultSet rs = st.executeQuery( sqlStr );
System.out.println( "操作数据表成功!" );
System.out.println( "----------------!" );
while(rs.next())
{ System.out.print(rs.getInt("job_id") + "\t");
System.out.print(rs.getString("job_desc") + "\t");
System.out.print(rs.getInt("min_lvl") + "\t");
System.out.print(rs.getString("max_lvl") + "\t");
System.out.println();
}
rs.close(); st.close(); con.close();
}
catch(Exception err){
err.printStackTrace(System.out);
} }} |
|