public class MySqlTest{
public static void main(String[] args) throws Exception{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?characterEncoding=utf-8","root","root");
String sql="select * from 表名";
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery(sql);
while(rs.next){
System.out.println("连接成数据库成功");
break;
}
rs.close();
st.close();
conn.close();
}
}
Statement执行不带参数的简单SQL语句,并返回它所生成结果的对象,每次执行SQL语句时,数据库都要编译该sql语句(非安全)