不废话,直接上代码
仅仅做一个备注,下次不用百度了。
String sql = "select * from test";
// 连接字符串,格式: "jdbc:数据库驱动名称://数据库服务器ip/数据库名称?user=用户名&password=密码&使用Unicode=布尔值&字符编码=编码"
String url = "jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1";
String username = "scott";
String password = "tiger";
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection conn = DriverManager.getConnection(url, username, password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE
, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery(sql);
rs.close();
stmt.close();
conn.close();