當前位置:首頁 » 操作系統 » java學生成績資料庫

java學生成績資料庫

發布時間: 2024-07-27 06:16:49

java鏁版嵁搴撴煡璇㈠姛鑳藉疄鐜(java鏁版嵁搴撴煡璇㈣鍙)

publicclassJdbcNoarg{

//鏌ヨ涓琛屾暟鎹

publicvoid(){

jdbc=new();

Connectioncon=null;

Statementst=null;

Stringsql;

ResultSetrst=null;

try{

//鑾峰彇鏁版嵁搴撹繛鎺

con=jdbc.();

//鍦ㄨ繛鎺ラ噷鎵撳紑涓鏉¢氶亾錛岃繑鍥濻tatement瀵硅薄

st=con.();

sql="select*fromstudent";

//鎶婃垜浠鎯寵佺粨鏋渟ql璇鍙ュ彂閫佺粰鏁版嵁搴擄紝鏁版嵁搴撹繑鍥炵殑鏁版嵁鐢╦avaResultSet鏉ユ帴鏀

rst=st.(sql);

//鑾峰彇緇撴灉闆嗙殑絎涓琛屾暟鎹9

rst.first();

//鑾峰彇緇撴灉闆嗘寚瀹氬垪鐨勬暟鎹

Stringname=rst.getString("name");

Stringinterest=rst.getString("interest");

System.out.println("name:"name";interest:"interest);

}catch(Exceptione){

e.();

}finally{

try{

if(rst!=null)

rst.close();

if(st!=null)

st.close();

if(con!=null)

con.close();

}catch(Exceptione2){

e2.();

}

}

}

1

② 臨近畢業,用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學生信息管理系統源代碼,帶有連接資料庫的,萬分感謝

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;
}
}
資料庫你自己弄吧,我沒時間弄了!初學得多動手哦

熱點內容
頻率計源碼 發布:2024-09-08 07:40:26 瀏覽:778
奧迪a6哪個配置帶後排加熱 發布:2024-09-08 07:06:32 瀏覽:100
linux修改apache埠 發布:2024-09-08 07:05:49 瀏覽:208
有多少個不同的密碼子 發布:2024-09-08 07:00:46 瀏覽:566
linux搭建mysql伺服器配置 發布:2024-09-08 06:50:02 瀏覽:995
加上www不能訪問 發布:2024-09-08 06:39:52 瀏覽:811
銀行支付密碼器怎麼用 發布:2024-09-08 06:39:52 瀏覽:513
蘋果手機清理瀏覽器緩存怎麼清理緩存 發布:2024-09-08 06:31:32 瀏覽:554
雲伺服器的優點與缺點 發布:2024-09-08 06:30:34 瀏覽:734
上傳下載賺錢 發布:2024-09-08 06:14:51 瀏覽:258