?? test.java
字號:
package cn.itcast.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
/**
* @param args
* @throws Exception
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws Exception {
Connection conn = JdbcUtils.getConnection();
System.out.println("class1:" + conn.getClass());
test();
}
static void test() throws Exception {
Class.forName("com.mysql.jdbc.Driver");
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
System.setProperty("jdbc.drivers", "com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/test?user=root&password=root";
String user = "root";
String password = "root";
Connection conn = DriverManager.getConnection(url, user, password);
System.out.println("class2:" + conn.getClass());
Statement st = conn.createStatement();
String sql = "select id, age, name from user";
ResultSet rs = st.executeQuery(sql);
while (rs.next()) {
System.out.println(rs.getInt("id"));
System.out.println(rs.getString("name"));
System.out.println(rs.getInt("age"));
// ...
}
rs.close();
st.close();
conn.close();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -