当前位置: 技术问答>java相关
用JDBC连接SQLSERVER的问题!一定给分!
来源: 互联网 发布时间:2015-04-07
本文导语: JDBC的驱动已经装好了, 在JSP中怎样写连接语句呢?(不是用JDBC-ODBC) 能否给个例子看看! | 你忘了说你的驱动名称了 我是用MS的驱动 | String driverClass = "com.microsoft.jdbc....
JDBC的驱动已经装好了,
在JSP中怎样写连接语句呢?(不是用JDBC-ODBC)
能否给个例子看看!
在JSP中怎样写连接语句呢?(不是用JDBC-ODBC)
能否给个例子看看!
|
你忘了说你的驱动名称了
我是用MS的驱动
我是用MS的驱动
|
String driverClass = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String connectUrl = "jdbc:microsoft:sqlserver://localhost:1433";
String userName = "sa";
String userPass = "sql";
Class.forName(driverClass);
Connection conn = DriverManager.getConnection(connectUrl,userName,userPass);
conn.setCatalog("dbName");
Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = null;
String sqlStr = "select ..... ";
rs = st.executeQuery(sqlStr);
while ( rs.next() ) {
//do something
}
rs.close();
st.close();
String connectUrl = "jdbc:microsoft:sqlserver://localhost:1433";
String userName = "sa";
String userPass = "sql";
Class.forName(driverClass);
Connection conn = DriverManager.getConnection(connectUrl,userName,userPass);
conn.setCatalog("dbName");
Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs = null;
String sqlStr = "select ..... ";
rs = st.executeQuery(sqlStr);
while ( rs.next() ) {
//do something
}
rs.close();
st.close();