时间:2021-07-01 10:21:17 帮助过:7人阅读
package cn.itcast.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import org.junit.Test; public class JDBCTest { @Test public void demo() throws SQLException, ClassNotFoundException{ //DriverManager.registerDriver(new Driver());//加载JDBC驱动 Class.forName("com.mysql.jdbc.Driver"); //加载JDBC驱动 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/day03","root","mima");//建立连接 Statement stmt = conn.createStatement();//将sql语句发送给数据库执行 ResultSet rs = stmt.executeQuery("select * from student"); while(rs.next()){ System.out.println(rs.getString("city")); } rs.close(); //释放资源 stmt.close(); conn.close(); } }
JDBCTest
标签:str mysql log 加载 getc 驱动 sel print mysq