求指导java连接数据库
答案:2 悬赏:60 手机版
解决时间 2021-03-24 16:52
- 提问者网友:戎马万世
- 2021-03-23 19:40
求指导java连接数据库
最佳答案
- 五星知识达人网友:空山清雨
- 2021-03-23 20:07
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class InsertData {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/exam", "root", "123456");
Statement stmt = conn.createStatement();
String sql = "insert into user(username,password) values('hansan','123456')";
int m =stmt.executeUpdate(sql);
System.out.println("插入"+m+"行数据");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class InsertData {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/exam", "root", "123456");
Statement stmt = conn.createStatement();
String sql = "insert into user(username,password) values('hansan','123456')";
int m =stmt.executeUpdate(sql);
System.out.println("插入"+m+"行数据");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯