求用Java实现程序注册和登陆并且连接MySQL数据库

2024-11-01 07:55:45
推荐回答(2个)
回答1:

假设登陆Oracle的数据库,连接方式
String driver = "oracle.jdbc.OracleDriver";
Connection cn = null;
Class.forName(driver);
String url = "jdbc:oracle:thin:@localhost:1521:ORACLE";
String user = "system";
String pwd = "密码";
cn = DriverManager.getConnection(url,user,pwd);
Statement st = cn.createStatement();
String sql = "Insert into loginfo (id,username,user,type) values( "id="+你的id+"username="+user+",password="+pwd+",type="+你的type);
st.executeUpdate(sql);
st.closed;
cn.closed;

Mysql Database
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/数据库名称",
"账户","密码");
localhost你的ip地址
3306 mysql的数据库端口号这个不用改

回答2:

我可以给你写这个代码