JDBC规范
package test.jdbc;
imp
imp
imp
imp
public class Base
{
public static void main(String[] args) throws Exception
{
template();
}
static void template() throws Exception
{
String url="jdbc:mysql://localhost:3306/jdbc";
String user="root";
String password="123";
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));
}
} finally
{
try
{
if (rs!=null)
rs.close();
} finally
{
try
{
if(st!=null)
st.close();
} finally
{
if(conn!=null)
conn.close();
}
}
}
}
}
1万+

被折叠的 条评论
为什么被折叠?



