「javasql学生」javasqlserver学生管理

博主:adminadmin 2022-12-24 06:06:07 60

今天给各位分享javasql学生的知识,其中也会对javasqlserver学生管理进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java+sql学生学籍管理

是单机的还是分布式的?

满意请采纳。

以上回答你满意么?

用java 和SQl server 编写的学生管理系统如何加载学生相片

使用JAVA在SQL Server 中存放图片

import java.sql.*;

import java.io.*;

/**

*

* pTitle: 从SQLServer数据库插入和获取图片/p

*

* pDescription: 用于对数据库image类型字段类型进行操作/p

*

* pCopyright: Copyright (c) 2008/p

*

* pCompany: 阿智(网转修改)/p

*

* @author not attributable

* @version 1.0

*/

public class ImgTack {

public Connection con = null; //连接数据库接口

public PreparedStatement pst = null; //预处理SQL接口

public ResultSet rs = null; //返回结果集接口

/**

* 构造时就加载驱动(本地API)

*/

public ImgTack() {

try {

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

}

catch (Exception ex) {

ex.printStackTrace();

}

}

/**

* 以二进制方式插入图片到数据库image类型字段

* insertImg(需要插入的图片完整路径或相对路径);

* @param imgFile String

*/

public void insertImg(String imgFile) {

FileInputStream fis = null;

File file = new File(imgFile);

try {

fis = new FileInputStream(file);

con = this.getConnection();

try {

pst = con.prepareStatement("insert temp values(?)");

pst.setBinaryStream(1, fis, (int) file.length());

pst.executeUpdate();

}

catch (SQLException ex) {

ex.printStackTrace();

}

finally {

this.closeAll();

}

}

catch (IOException ex1) {

ex1.printStackTrace();

}

finally {

try {

fis.close();

}

catch (IOException ex2) {

ex2.printStackTrace();

}

}

}

/**

* 以二进制方式从数据库获取图片到本地机子

* getImg(需要保存图片的完整路径或相对路径);

* @param imgFile String

*/

public void getImg(String imgFile) {

File file = new File(imgFile);

FileOutputStream fos = null;

InputStream is = null;

try {

fos = new FileOutputStream(file);

con = this.getConnection();

pst = con.prepareStatement("select img from temp where id=1");

rs = pst.executeQuery();

if (!rs.next()) {

System.out.println("没有记录");

return;

}

is = rs.getBinaryStream(1);

byte b[] = new byte[10 * 1024];

while (is.read(b, 0, 10240) != -1) {

fos.write(b, 0, 10240);

}

}

catch (Exception ex) {

ex.printStackTrace();

}

finally {

this.closeAll();

try {

is.close();

fos.close();

}

catch (IOException ex1) {

ex1.printStackTrace();

}

}

}

/**

* 获取连接数据库接口

* @return Connection

*/

public Connection getConnection() {

try {

return DriverManager.getConnection(

"jdbc:microsoft:sqlserver://localhost:1433;databaseName=pubs;", "sa", null);

}

catch (Exception ex) {

ex.printStackTrace();

}

return null;

}

/**

* 关闭所有接口

*/

public void closeAll() {

try {

if (rs != null) {

rs.close();

}

if (pst != null) {

pst.close();

}

if (con != null) {

con.close();

}

}

catch (Exception ex) {

ex.printStackTrace();

}

}

}

java操作sql数据库,增加数据库的学生信息,求代码,谢谢了

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

String DBURL = "jdbc:oracle:thin:@IP地址:1521:数据库名" ;

String DBUSER = "数据库用户名" ;

String DBPASSWORD= "密码" ;

Connection con = null ;

PreparedStatement pstmt = null ;

String sql = "insert into 表a (字段a,字段b) values"+ " ('"

+ a

+ "','"

+b+"')";

Class.forName(DBDRIVER) ;

con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;

pstmt = con.prepareStatement(sql) ;

try {

pstmt.executeUpdate();

} catch (Exception e) {

e.printStackTrace();

conn.rollback();

} finally{

pstmt.close();

con.close();

}

给点分

临近毕业,用java做了个学生信息管理系统,需要用到sql数据库,请问怎么连接,急用,谢谢各位

package test;

import java.sql.*;

import cn.com.sdata.util.SDGetConnection;

/**

*

* @author user

*mssql数据库连接操作

*/

public class MssqlConnTest {

String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动

String dbURL = "jdbc:sqlserver://127.0.0.1:1433; DatabaseName=test"; //连接服务器和数据库sample

String userName = "sa"; //默认用户名

String userPwd = "000000"; //密码

Connection dbConn;

public Connection getConnection()

{

try

{

Class.forName(driverName);

dbConn = DriverManager.getConnection(dbURL, userName, userPwd);

System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful!

return dbConn;

} catch (Exception e)

{

e.printStackTrace();

}

return null;

}

public void closeConnection()

{

try {

dbConn.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public static void main(String[] srg)

{

// DBConnectionManager DBConnectionManager1 = new DBConnectionManager();

try

{

System.out.println("success");

MssqlConnTest test = new MssqlConnTest();

Connection conn = test.getConnection();

System.out.println("Connection Successful!"); //如果连接成功 控制台输出Connection Successful!

Statement stmt=conn.createStatement();

ResultSet rs=stmt.executeQuery("select top 1 * from DOI");

while(rs.next())

{

System.out.print("\tfirst: "+rs.getString(1));

System.out.print("\tsecond: "+rs.getString(2));

}

//*/

}catch(Exception e)

{

e.printStackTrace();

}

}

}

怎么用java+sql数据库做一个学生信息管理系统

Student 类

public class Student

{

private int id;

private int age;

private int score;

private String name;

public Student()

{

}

public Student(int id, int age, int score, String name)

{

this.id = id;

this.age = age;

this.score = score;

this.name = name;

}

public int getId()

{

return id;

}

public void setId(int id)

{

this.id = id;

}

public int getAge()

{

return age;

}

public void setAge(int age)

{

this.age = age;

}

public int getScore()

{

return score;

}

public void setScore(int score)

{

this.score = score;

}

public String getName()

{

return name;

}

public void setName(String name)

{

this.name = name;

}

@Override

public String toString()

{

return "学号:" + id + " 姓名:" + name + " 年龄:" + age + " 成绩:" + score;

}

}

Manager类

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

public class Manager

{

private ListStudent list;

public Manager(ListStudent list)

{

this.list = list;

}

public ListStudent getList()

{

return list;

}

public void setList(ListStudent list)

{

this.list = list;

}

//添加学生

public void add(Student s)

{

list.add(s);

}

//根据学生学号返回学生年龄

public int search(int id)

{

for(IteratorStudent iter = list.iterator(); iter.hasNext();)

{

Student s = iter.next();

if(s.getId() == id)

{

return s.getAge();

}

}

return -1;

}

//删除学生

public void remove(int id)

{

for(IteratorStudent iter = list.iterator(); iter.hasNext();)

{

Student s = iter.next();

if(s.getId() == id)

{

list.remove(s);

}

}

}

//计算总成绩

public int allScore()

{

int score = 0;

int temp = 0;

for(IteratorStudent iter = list.iterator(); iter.hasNext();)

{

Student s = iter.next();

temp = s.getScore();

score += temp;

}

return score;

}

//修改成绩

public void update(int id)

{

for(IteratorStudent iter = list.iterator(); iter.hasNext();)

{

Student s = iter.next();

if(s.getId() == id)

{

s.setScore(s.getScore() + 10);

}

}

}

}

测试类 Client

import java.util.ArrayList;

import java.util.List;

public class Client

{

public static void main(String[] args)

{

ListStudent list = new ArrayListStudent();

Manager manager = new Manager(list);//创建一个管理者

Student s1 = new Student();//无参构造方法创建的学生实例

//通过方法设置s1的属性

s1.setId(201105);

s1.setAge(20);

s1.setScore(100);

s1.setName("zhangsan");

Student s2 = new Student(201101,21,98,"lisi");//通过带参数的构造方法创建实例

Student s3 = new Student(201108,25,95,"zhaoliu");

Student s4 = new Student(201110,23,80,"xiaoming");

Student s5 = new Student(201106,28,78,"hello");

//放到集合当中

manager.getList().add(s1);//添加学生

manager.getList().add(s2);

manager.getList().add(s3);

manager.getList().add(s4);

manager.getList().add(s5);

System.out.println(list);

System.out.println(manager.allScore());

System.out.println(manager.search(201110));//根据学生学号查询学生年龄

manager.remove(201110);//删除学生

manager.update(201101);//修改成绩

}

}

可以完成你上述的基本要求,如果改动可以自行修改 很简单。

javasql学生的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于javasqlserver学生管理、javasql学生的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-24,除非注明,否则均为首码项目网原创文章,转载请注明出处。