import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Demo {
public static void main(String[] args) throws SQLException
{
test();
}
static void test() throws SQLException
{
// 1、注册驱动
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
// 2、建立连接
String url ="jdbc:mysql://localhost:3306/library";
String user ="root";
String password ="shuangyuzuo";
Connection conn = DriverManager.getConnection(url,user,password);
// 3、创建语句
Statement st = conn.createStatement();
// 4、执行结果
ResultSet rs = st.executeQuery("select * from book");
// 5、处理结果
while (rs.next())
{
System.out.println(rs.getObject("name")+"\t"+rs.getObject("number")+"\t"+rs.getObject("auther")+"\t"+rs.getObject("press"));
}
rs.close();
st.close();
conn.close();
}
}
————————————————
版权声明:本文为CSDN博主「明明如月学长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/w605283073/article/details/46572483