public class BaseDao {
public static void main(String args[]) {
// Create a variable for the connection string.
// String connectionUrl = "jdbc:sqlserver://127.0.0.1:1433;"
// + "databaseName=Test;integratedSecurity=true;";
String url = "jdbc:sqlserver://127.0.0.1:1433;databaseName=newuStandard2012;user=sa;password=newu"; //sa身份连接 ;user=sa;password=newu
// String url2 = "jdbc:sqlserver://127.0.0.1:1433;databaseName=Test;integratedSecurity=true;";//windows集成模式连接
// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
// Establish the connection.
System.out.println("begin.");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); //SQLServerDriver
System.out.println("888888");
con = DriverManager.getConnection(url);
System.out.println("end.");
// Create and execute an SQL statement that returns some data.
String SQL = "SELECT * FROM newu_log_alarm";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
// Iterate through the data in the result set and display it.
while (rs.next()) {
System.out.println(rs.getString(1) + " " + rs.getString(2)+" " + rs.getString(3)+" " + rs.getString(4)+" " + rs.getString(5)+" " + rs.getString(6)+" " + rs.getString(7)+" " + rs.getString(8)+" " + rs.getString(9)+" " + rs.getString(10)+" " + rs.getString(11)+" " + rs.getString(12)+" " + rs.getString(13)+" " + rs.getString(14));
}
}
// Handle any errors that may have occurred.
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null)
try {
rs.close();
} catch (Exception e) {
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
}
if (con != null)
try {
con.close();
} catch (Exception e) {
}
}
}
}各位我想问问如果我想在main方法之外在加两个方法public ResultSet getResultSet(String sql1, Object[] params, int pageNow)
和public boolean modify(String sql, Object[] params)
那该怎么做了,谢谢各位师哥,师姐了
写成员方法,把需要的部分抽取出来,你要理解面向对象,这个应该很容易的