import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection conn=null;
try {
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/myschool","root","1258");
String sql="insert admin values('zhangsan','123456')";
System.out.println("连接成功");
} catch (SQLException e) {
e.printStackTrace();
}
finally {
if(conn!=null) {
try {
conn.close();
System.out.println("关闭连接成功");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
代码没报错 连接不上