package itcast;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Base {
/**
* @param args
*/
public static void main(String[] args) {
}
static void template() throws Exception {
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String password = "";
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
// 1注册驱动
Class.forName("com.mysql.jdbc.Driver");
// 2建立链接
conn = DriverManager.getConnection(url, user, password);
// 3创建语句
st = conn.createStatement();
// 4 执行语句
rs = st.executeQuery("select * from user");
// 5处理结果
while (rs.next()) {
System.out.println(rs.getObject(1) + "\t" + rs.getObject(2)
+ "\t" + rs.getObject(3) + "\t" + rs.getObject(4)
+ "\t" + rs.getObject(5) + "\t");
}
} finally {
try {
if (rs != null) {
rs.close();
}
} finally {
try {
if (st != null) {
st.close();
}
} finally {
if (conn != null) {
conn.close();
}
}
}
}
}
}
相关文章
- 08-30sapi语音朗读的简单用法(Unity中)
- 08-30香橙派OrangePi zero2开发板连接3.5寸SPI LCD显示屏的使用方法
- 08-30PTA QQ帐户的申请与登陆(map的简单应用)
- 08-30浙大 PAT 甲级 1079 Total Sales of Supply Chain 最简单的深度优先搜索 DFS
- 08-30http请求连接
- 08-30简单工厂设计模式实现
- 08-30解决Cisco VPN Client:Reason 442: Failed to Enable Virtual Adapter VPN连接问题
- 08-30简单工厂模式
- 08-30POJ 3264 Balanced Lineup 简单RMQ
- 08-30AsyncSocket长连接棒包装问题解决