学生信息系统代码呈上(已连接数据库)://仅供参考,粘贴复制运行不了

学生信息系统代码呈上(已连接数据库)://仅供参考,粘贴复制运行不了

package text1;
import java.sql.*;
public class Student_main{
  public static void main(String args[]) {
    try {
      Class.forName("com.mysql.jdbc.Driver");                                  //加载MYSQL JDBC驱动程序  
      //Class.forName("org.gjt.mm.mysql.Driver");
     System.out.println("Success loading Mysql Driver!");
    }
    catch (Exception e) {
      System.out.print("Error loading Mysql Driver!");
      e.printStackTrace();
    }
    try {
      Connection connect = DriverManager.getConnection(
          "jdbc:mysql://127.0.0.1:3306/test","root","root");
     
           //连接URL为   jdbc:mysql//服务器地址/数据库名  ,后面的2个参数分别是登陆用户名和密码
      System.out.println("Success connect Mysql server!");
      Statement stmt = connect.createStatement();
      ResultSet rs = stmt.executeQuery("select * from t1");
                                                              //user 为你表的名称
while (rs.next()) {
        System.out.print(rs.getString("id")+" ");
        System.out.print(rs.getString("name")+" ");
        System.out.print(rs.getString("age")+" ");
        System.out.print(rs.getString("score")+" ");
       // System.out.println(rs.getInt("StuAge"));
      }
    }
    catch (Exception e) {
      System.out.print("get data error!");
      e.printStackTrace();
    }
    StudentOperator.menu();
  }
}
//其余代码和上一篇一样

猜你喜欢

转载自www.cnblogs.com/daisy99lijing/p/9696661.html
今日推荐