?? jdbctest.java
字號(hào):
package com.cric.onlineshopclothes.util;
public class JdbcTest {
public static void main(String[] args) {
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String userName = "sa";
String passWord = "sa";
String dbUrl = "jdbc:microsoft:sqlserver://localhost:1433;databaseName=OnlineShopClothes";
java.sql.Connection conn = null;
java.sql.Statement stmt = null;
java.sql.ResultSet rs = null;
try {
Class.forName(driverName);
System.out.print("Driver OK!");
conn = java.sql.DriverManager.getConnection(dbUrl, userName,
passWord);
System.out.print("conn OK11!");
stmt = conn.createStatement();
// String sqlStr="insert into users values('003','marry')";
// String sqlStr="update users set userName='marry' where
// userId='001'";
//String sqlStr = "delete users where userId='001'";
// stmt.execute(sqlStr);
String sqlstr1 = "select * from admin";
rs = stmt.executeQuery(sqlstr1);
while (rs.next()) {
String userId = rs.getString("uId").trim();
String userN = rs.getString("userName").trim();
String userP = rs.getString("passWord").trim();
System.out.println( userId+"-" + userN+"-"+userP);
}
} catch (java.lang.ClassNotFoundException e) {
e.printStackTrace();
} catch (java.sql.SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
} catch (java.sql.SQLException e) {
e.printStackTrace();
}
try {
if (stmt != null)
stmt.close();
} catch (java.sql.SQLException e) {
e.printStackTrace();
}
try {
if (conn != null)
conn.close();
} catch (java.sql.SQLException e) {
e.printStackTrace();
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -