(高分)急求连接数据库的JAVA学生信息管理系统源代码

2025-04-09 06:06:08
推荐回答(1个)
回答1:

你要连的数据库是SQL 还是ORACLE
但是代码都查不多

下面的是连接SQL数据库的代码

你需要先创建个数据库,还有表,表的字段是登陆名和密码
下面的"SA" 是登陆名 "111111" 是密码
ORACLE 和这个查不多

import java.sql.*;//做数据库时候必须要引入的包
import com.microsoft.jdbc.sqlserver.SQLServerDriver;
public class DBFactory {

Connection Conn=null;

PreparedStatement Stmt=null;

ResultSet Rs=null;

String driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver";

String OracleUserName="sa";

String OracleUserPwd="111111";

String ConnUrl="jdbc:sqlserver://localhost:1433;databaseName=news";

public Connection getConnection()

{

try {

Class.forName(driverName);

} catch (ClassNotFoundException ex) {

System.out.println("加载驱动程序有错误");

}

try {

Conn = DriverManager.getConnection(ConnUrl, OracleUserName,OracleUserPwd);

} catch (SQLException ex1) {

System.out.print("取得连接的时候有错误,请核对用户名和密码");

}

return Conn;

}
这个是连接ORACLE数据库代码
import java.sql.*;
import oracle.jdbc.driver.OracleDriver;
public class DBFactory {

Connection Conn=null;

PreparedStatement Stmt=null;

ResultSet Rs=null;

String driverName="oracle.jdbc.driver.OracleDriver";

String OracleUserName="scott";

String OracleUserPwd="tiger";

String ConnUr1="jdbc:oracle:thin:@locahost:1521:Ora";

public Connection getConnection()

{

try {

Class.forName(driverName);

} catch (ClassNotFoundException ex) {

System.out.println("加载驱动程序有错误");

}

try {

Conn = DriverManager.getConnection(ConnUr1, OracleUserName,OracleUserPwd);

} catch (SQLException ex1) {

System.out.print("取得连接时有错误,请核对用户名和密码");

}

return Conn;

}
希望能追加分数谢谢!