import com.mysql.jdbc.Driver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class TestJDBCConnection {
public static void main(String[] args) {
Statement statement=null;
Connection connection=null;
try {
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
String url="jdbc:mysql://127.0.0.1:3306/mobilemallsystem";
String user="root";
String password="123456";
connection= DriverManager.getConnection(url,user, password);
statement= connection.createStatement();
String sql="insert into usermessage(uname,upassword) values('666','666')";
statement.executeUpdate(sql);
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally {
if(statement!=null){
try {
statement.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
if(connection!=null){
try {
connection.close();
} catch (SQLException throwables) {
throwables.printStackTrace();
}
}
}
}
}
你的点赞和关注,是我继续坚持下去的动力,如果可以请一键三连,谢谢!
个人知识水平有限,如果博客中有误,望指正。
如果欲交流学习,请私信我,我一定会在看到消息时及时回复你。
|