java数据库管理系统(建立数据库)
各位老铁们,大家好,今天由我来为大家分享java数据库管理系统,以及建立数据库的相关问题知识,希望对大家有所帮助。如果可以帮助到大家,还望关注收藏下本站,您的支持是我们最大的动力,谢谢大家了哈,下面我们开始吧!
用java设计一个数据库管理系统
import java.sql.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
//import java.awt.event.*;
public class DisplayDemo extends JFrame
//implements ActionListener
{
// private String dbURL="jdbc:microsoft:sqlserver://202.115.26.181:1433";//数据库标识名
private String user="devon";//数据库用户
private String password="book";//数据库用户密码
private JTable table;
private JButton ok,canel;
public DisplayDemo(){
super("显示数据库查询结果");//调用父类构造函数
String[] columnNames={"用户名","年龄","性别","Email"};//列名
Object[][] rowData=new Object[5][4];//表格数据
ok=new JButton("确定");
canel=new JButton("取消");
// ok.addActionListener(this);
// canel.addActionListener(this);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:example","sa","");
// Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");//加载驱动器
// Connection con=DriverManager.getConnection(dbURL,user,password);//获取连接
String sqlStr="select* from users";//查询语句
PreparedStatement ps=con.prepareStatement(sqlStr);//获取PreparedStatement对象
ResultSet rs=ps.executeQuery();//执行查询
String name,sex,email;//查询结果
int age;
int count=0;
while(rs.next()){//遍历查询结果
rowData[count][0]=rs.getString("name");//初始化数组内容
rowData[count][1]=Integer.toString(rs.getInt("age"));
rowData[count][2]=rs.getString("sex");
rowData[count][3]=rs.getString("email");
count++;
}
con.close();//关闭连接
}
catch(Exception ex){
ex.printStackTrace();//输出出错信息
}
Container container=getContentPane();//获取窗口容器
//container.setLayout(null);
container.add(ok);container.add(canel); ok.setBounds(10,120,70,20);
canel.setBounds(100,120,70,20);
table=new JTable(rowData,columnNames);//实例化表格
table.getColumn("年龄").setMaxWidth(25);//设置行宽
container.add(new JScrollPane(table),BorderLayout.CENTER);//增加组件
setSize(300,200);//设置窗口尺寸
setVisible(true);//设置窗口可视
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//关闭窗口时退出程序
}
public static void main(String[] args){
new DisplayDemo();
}
}
-----------------
这是其中一个例子你照着上面做就可以了
java是数据库管理系统吗
java并不是数据库管理系统,数据库管理系统时基于java实现的。
Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程。
Java设计成支持在网络上应用,它是分布式语言。Java既支持各种层次的网络连接,又以Socket类支持可靠的流(stream)网络连接,所以用户可以产生分布式的客户机和服务器。网络变成软件应用的分布运载工具。Java程序只要编写一次,就可到处运行。
Java的发展前景:
计算机的诞生及广泛应用推动了IT领域的发展,但21世纪的计算机早已不是访问INTERNET的唯一的途径。各类更具信息化的电子产品逐渐进入IT领域,推动了PC时代的大发展。
由于各种消费信息的急剧增加,传统的客户机的各方面条件均不如PC,PC的发展对服务器的应用管理体统也提出了更高标准。
Java语言完全满足了PC的条件,在减少内存,直接在各类电子产品中运行,在网络中可被任何设备所识别,充分利用网络资源等方面有所突破创新,为PC时代的发展创造了有利条件。
急求java学生信息管理系统源代码,带有连接数据库的,万分感谢
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
public class MainFrame extends JFrame implements ActionListener{
InsertPanel ip= null;
SelectPanel sp= null;
JPanel pframe;
JButton jb1,jb2,jb3;
JMenuItem jm11,jm21,jm22,jm23,jm31,jm32,jm41,jm42;
CardLayout clayout;
public MainFrame(String s){
super(s);
JMenuBar mb= new JMenuBar();
this.setJMenuBar(mb);
JMenu m1= new JMenu("系统");
JMenu m2= new JMenu("基本信息");
JMenu m3= new JMenu("成绩");
JMenu m4= new JMenu("奖惩");
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
jm11= new JMenuItem("退出系统");
jm21= new JMenuItem("输入");
jm22= new JMenuItem("查询");
jm23= new JMenuItem("更改");
jm31= new JMenuItem("输入成绩");
jm32= new JMenuItem("查询成绩");
jm41= new JMenuItem("奖励");
jm42= new JMenuItem("处分");
m1.add(jm11);
m2.add(jm21);
m2.add(jm22);
m2.add(jm23);
m3.add(jm31);
m3.add(jm32);
m4.add(jm41);
m4.add(jm42);
Icon i1= new ImageIcon();
Icon i2= new ImageIcon();
Icon i3= new ImageIcon();
jb1= new JButton(i1);
jb1.setToolTipText("输入");
jb2= new JButton(i2);
jb2.setToolTipText("查询");
jb3= new JButton(i3);
jb3.setToolTipText("退出");
JToolBar tb= new JToolBar("系统工具");
tb.add(jb1);
tb.add(jb2);
tb.add(jb3);
add(tb,BorderLayout.NORTH);
jm11.addActionListener(this);
jm21.addActionListener(this);
jm22.addActionListener(this);
jb1.addActionListener(this);
jb2.addActionListener(this);
jb3.addActionListener(this);
clayout= new CardLayout();
pframe= new JPanel(clayout);
add(pframe);
JPanel mainp= new JPanel(new BorderLayout());
JLabel mainl= new JLabel("学生信息管理平台",SwingConstants.CENTER);
mainl.setFont(new Font("serif",Font.BOLD,30));
mainp.add(mainl);
pframe.add(mainp,"main");
clayout.show(pframe,"main");
}
public void actionPerformed(ActionEvent e){
if(e.getSource()== jm21|| e.getSource()== jb1){
if(ip== null){
ip= new InsertPanel();
pframe.add(ip,"insert");
}
clayout.show(pframe,"insert");
this.setTitle("输入学生信息");
}
else if(e.getSource()== jm22|| e.getSource()== jb2){
if(sp== null){
sp= new SelectPanel();
pframe.add(sp,"select");
}
clayout.show(pframe,"select");
this.setTitle("查询学生信息");
}
else if(e.getSource()== jm11|| e.getSource()== jb3){
System.exit(0);
}
}
}
第二个:
import javax.swing.JFrame;
public class MainTest{
public static void main(String [] args){
MainFrame f= new MainFrame("学生信息管理平台");
f.setSize(400,300);
f.setLocation(350,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第二个:
import java.sql.Connection;
import java.sql.DriverManager;
public class MySQLConnection{
static Connection getCon(){
Connection con= null;
try{
Class.forName("com.mysql.jdbc.Driver");
con= DriverManager.getConnection("jdbc:mysql://localhost/test","root","123");
}
catch(Exception e){
System.out.println("建立数据库连接遇到异常!");
}
return con;
}
}
第四个:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class SelectPanel extends JPanel implements ActionListener{
JButton jb;
JTextField jt;
JTextField jt1,jt2,jt3,jt4;
public SelectPanel(){
JLabel jl= new JLabel("请输入学号:",SwingConstants.CENTER);
jt= new JTextField();
jb= new JButton("确定");
JPanel jp1= new JPanel(new GridLayout(1,3));
jp1.add(jl);
jp1.add(jt);
jp1.add(jb);
JLabel j1,j2,j3,j4;
j1= new JLabel("学号:",SwingConstants.CENTER);
j2= new JLabel("姓名:",SwingConstants.CENTER);
j3= new JLabel("性别:",SwingConstants.CENTER);
j4= new JLabel("年龄:",SwingConstants.CENTER);
jt1= new JTextField(6);
jt1.setEditable(false);
jt2= new JTextField(6);
jt2.setEditable(false);
jt3= new JTextField(6);
jt3.setEditable(false);
jt4= new JTextField(6);
jt4.setEditable(false);
JPanel jp2= new JPanel(new BorderLayout());
JPanel jp3= new JPanel(new GridLayout(4,2));
jp2.add(new JLabel(""),BorderLayout.NORTH);
jp3.add(j1);
jp3.add(jt1);
jp3.add(j2);
jp3.add(jt2);
jp3.add(j3);
jp3.add(jt3);
jp3.add(j4);
jp3.add(jt4);
jp2.add(jp3);
this.setLayout(new BorderLayout());
add(jp1,BorderLayout.NORTH);
add(jp2);
jb.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()== jb){
String stuNo= jt.getText().trim();
Student s= new Student();
boolean b= true;
try{
b= s.selectByStuNo(stuNo);
}
catch(Exception ex){
System.out.println("查询学生信息遇到异常!");
}
if(b){
jt1.setText(s.getStuNo());
jt2.setText(s.getName());
jt3.setText(s.getGender());
int a= s.getAge();
Integer i= new Integer(a);
jt4.setText(i.toString());
}
else{
JOptionPane.showMessageDialog(null,"无此学生!");
}
}
}
}
第五个:
import javax.swing.JFrame;
public class SelectTest{
public static void main(String [] args){
JFrame f= new JFrame("查询学生信息");
SelectPanel p= new SelectPanel();
f.add(p);
f.setSize(400,300);
f.setLocation(300,250);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
第六个:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
public class Student{
String stuNo;
String name;
String gender;
int age;
public Student(){}
public Student(String stuNo,String name,String gender, int age){
this.stuNo= stuNo;
this.name= name;
this.gender= gender;
this.age= age;
}
public String getStuNo(){
return stuNo;
}
public void setStuNo(String stuNo){
this.stuNo= stuNo;
}
public String getName(){
return name;
}
public void setName(String name){
this.name= name;
}
public String getGender(){
return gender;
}
public void setGender(String gender){
this.gender= gender;
}
public int getAge(){
return age;
}
public void setAge(int age){
this.age= age;
}
public boolean insertStudent(){
boolean b= true;
try{
Connection con= MySQLConnection.getCon();
Statement statement= con.createStatement();
String sql="insert into student values('"+ stuNo+"','"+ name+"','"+ gender+"',"+ age+")";
sql= new String(sql.getBytes("gb2312"),"ISO8859_1");
statement.executeUpdate(sql);
con.close();
}
catch(Exception e){
b= false;
System.out.println("插入数据库遇到异常!");
}
return b;
}
public boolean selectByStuNo(String stuNo)throws Exception{
boolean b= true;
Connection con= MySQLConnection.getCon();
Statement statement= con.createStatement();
String sql="select* from student where stuNo="+ stuNo;
ResultSet rs= statement.executeQuery(sql);
if(rs!= null&& rs.next()){
String no= rs.getString(1);
this.setStuNo(no);
String n= rs.getString(2);
n= new String(n.getBytes("ISO8859_1"),"gb2312");
this.setName(n);
String g= rs.getString(3);
g= new String(g.getBytes("ISO8859_1"),"gb2312");
this.setGender(g);
this.setAge(rs.getInt(4));
b= true;
}
rs.close();
statement.close();
con.close();
return b;
}
}
数据库你自己弄吧,我没时间弄了!初学得多动手哦
java数据库管理系统的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于建立数据库、java数据库管理系统的信息别忘了在本站进行查找哦。