基于JAVA技术下的图书馆数据库
发布网友
发布时间:2024-10-04 13:26
我来回答
共2个回答
热心网友
时间:2024-10-18 05:34
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class keshe{
public static void main(String args[])
{
new jiemian().geshi();
}
}
class jiemian extends JFrame{
JTextField text1,text2,text3,text4,text5;
JLabel label1,label2;
JTextArea area1;
JButton button1;
public void geshi(){
setBounds(100,50,1000,700);
setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel p1=new JPanel(new FlowLayout());
text1=new JTextField(10);
text2=new JTextField(10);
label1=new JLabel("书号");
label2=new JLabel("作者名");
button1=new JButton("确定");
button1.addActionListener(new shiqing(this));
p1.add(label1);
p1.add(text1);
p1.add(label2);
p1.add(text2);
p1.add(button1);
add(p1,"North");
area1=new JTextArea();
text3=new JTextField(5);
text4=new JTextField(5);
text5=new JTextField(5);
add(text3,"East");
add(area1,"Center");
add(text4,"West");
add(text5,"South");
setVisible(true);
}
}
class shiqing implements ActionListener{
jiemian jiemian1=null;
public shiqing(jiemian jiemian1)
{
this.jiemian1=jiemian1;
}
public void actionPerformed(ActionEvent e)
{
// int d=Integer.parseInt(jiemian1.text1.getText());
String url="jdbc:odbc:chensi";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException ex)
{
System.out.println("无法装载驱动");
return;
}
try{ //连接数据库
Connection con= DriverManager.getConnection(url,"sa","7758521");
Statement sm=con.createStatement();
//sm.executeUpdate("insert into book values(11,'杂志','萌芽','陈斯',null,null,null,null,null)");
//sm.executeUpdate("delete from book where bname =11");
ResultSet rs=sm.executeQuery("select * from book" );
while(rs.next())
{
String s1=rs.getString(1);
String s2=rs.getString(2);
String s3=rs.getString(3);
String s4=rs.getString(4);
String s5=rs.getString(5);
String s6=rs.getString(6);
String s7=rs.getString(7);
String s8=rs.getString(8);
//jiemian1.area1.setText(s1+" "+s2+" "+s3+" "+s4+" "+s5+" "+s6+" "+s7+" "+s8+" "+"\n");
if(s1.trim().equals(jiemian1.text1.getText().trim()))
{
jiemian1.area1.append(s1+" "+s2+" "+s3+" "+s4+" "+s5+" "+s6+" "+s7+" "+s8+" "+"\n");
}
}
sm.close();
热心网友
时间:2024-10-18 05:40
学吧,数据库最少要会2种的。
先mysql,简单好用。然后学个复杂的大型数据库。
另外图书馆的数据库不简单的,要好好设计的。
热心网友
时间:2024-10-18 05:38
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class keshe{
public static void main(String args[])
{
new jiemian().geshi();
}
}
class jiemian extends JFrame{
JTextField text1,text2,text3,text4,text5;
JLabel label1,label2;
JTextArea area1;
JButton button1;
public void geshi(){
setBounds(100,50,1000,700);
setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel p1=new JPanel(new FlowLayout());
text1=new JTextField(10);
text2=new JTextField(10);
label1=new JLabel("书号");
label2=new JLabel("作者名");
button1=new JButton("确定");
button1.addActionListener(new shiqing(this));
p1.add(label1);
p1.add(text1);
p1.add(label2);
p1.add(text2);
p1.add(button1);
add(p1,"North");
area1=new JTextArea();
text3=new JTextField(5);
text4=new JTextField(5);
text5=new JTextField(5);
add(text3,"East");
add(area1,"Center");
add(text4,"West");
add(text5,"South");
setVisible(true);
}
}
class shiqing implements ActionListener{
jiemian jiemian1=null;
public shiqing(jiemian jiemian1)
{
this.jiemian1=jiemian1;
}
public void actionPerformed(ActionEvent e)
{
// int d=Integer.parseInt(jiemian1.text1.getText());
String url="jdbc:odbc:chensi";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(java.lang.ClassNotFoundException ex)
{
System.out.println("无法装载驱动");
return;
}
try{ //连接数据库
Connection con= DriverManager.getConnection(url,"sa","7758521");
Statement sm=con.createStatement();
//sm.executeUpdate("insert into book values(11,'杂志','萌芽','陈斯',null,null,null,null,null)");
//sm.executeUpdate("delete from book where bname =11");
ResultSet rs=sm.executeQuery("select * from book" );
while(rs.next())
{
String s1=rs.getString(1);
String s2=rs.getString(2);
String s3=rs.getString(3);
String s4=rs.getString(4);
String s5=rs.getString(5);
String s6=rs.getString(6);
String s7=rs.getString(7);
String s8=rs.getString(8);
//jiemian1.area1.setText(s1+" "+s2+" "+s3+" "+s4+" "+s5+" "+s6+" "+s7+" "+s8+" "+"\n");
if(s1.trim().equals(jiemian1.text1.getText().trim()))
{
jiemian1.area1.append(s1+" "+s2+" "+s3+" "+s4+" "+s5+" "+s6+" "+s7+" "+s8+" "+"\n");
}
}
sm.close();
热心网友
时间:2024-10-18 05:38
学吧,数据库最少要会2种的。
先mysql,简单好用。然后学个复杂的大型数据库。
另外图书馆的数据库不简单的,要好好设计的。