当前位置: 代码迷 >> Java相关 >> [求助]一个CS模式的学生成绩管理系统
  详细解决方案

[求助]一个CS模式的学生成绩管理系统

热度:136   发布时间:2007-07-07 18:57:47.0
[求助]一个CS模式的学生成绩管理系统
最近做课程设计,是一个CS模式的学生成绩管理系统,界面什么的都写好了,但数据库总是连接不上,原因也很奇怪,我想问大家谁有这样的原码,可以给我参考一下,好快点完成,下星期1就要就交了。。。。
谢谢大家~
搜索更多相关的解决方案: 模式  系统  学生  管理  

----------------解决方案--------------------------------------------------------
你要连什么数据库说清楚啊
----------------解决方案--------------------------------------------------------

数据库是SQL 2000 jdbc,数据库文件我也弄好了
是很简单........


----------------解决方案--------------------------------------------------------
import java.sql.*;

public class TestDB {
public static void main(String[] args) {
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=pubs";
String userName = "sa";
String userPwd = "";
Connection dbConn

try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
}
Catch (Exception e) {
e.printStackTrace();
}
}
}


----------------解决方案--------------------------------------------------------

首先你得安装好


SQL Server 2000 driver for JDBC

具体可能出错我也不是很清楚,因为也不太了解,可以问下别人,或者网上搜下:

看下这个对你有帮助吗:

http://tech.163.com/05/0830/15/1SDQL2CI00091589


----------------解决方案--------------------------------------------------------
我现在应该这些都弄好了,但还是不知道为什么,冰封说应该是SQL没打SP3补丁或者端口错误,我重打了补丁也看端口没问题,但还是不行
所以想要一个原码看看
就是一个成绩管理系统的原码参考一下
----------------解决方案--------------------------------------------------------
QUOTE:
以下是引用xw2014在2007-7-7 20:30:55的发言:
我现在应该这些都弄好了,但还是不知道为什么,冰封说应该是SQL没打SP3补丁或者端口错误,我重打了补丁也看端口没问题,但还是不行
所以想要一个原码看看
就是一个成绩管理系统的原码参考一下    

没在论坛里见过,有发过的,但好像没有代码. 是不是防火墙的问题.
----------------解决方案--------------------------------------------------------
这是错误:
java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at SqlUtil.acquireConnection(SqlUtil.java:34)
at MainApp.connectToDB(MainApp.java:89)
at MainApp.<init>(MainApp.java:68)
at MainApp.main(MainApp.java:206)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at MainApp.hideSplashScreen(MainApp.java:128)
at MainApp$3.run(MainApp.java:77)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
主界面程序:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.sql.*;
import java.util.*;
class MainApp extends JFrame
{
//系统启动时的等待画面
private JFrame splashScreen=null;
//管理菜单
private JMenu MMenu=new JMenu("管理");

private JMenuItem StudentResultM=new JMenuItem("学生成绩管理");

//设置菜单
private JMenu SetMenu=new JMenu("设置");
private JMenuItem SysConfig=new JMenuItem("系统参数设置");
//帮助菜单
private JMenu HelpMenu=new JMenu("帮助");
JMenuItem aboutMe=new JMenuItem("关于本程序");
//内容窗格
private Container contentPane;
//当前内容窗格中的面板
private JPanel selectedPanel;
//状态信息
JLabel labStatusContent;
//登录用户
private JLabel labUserContent;
//数据库连接
Connection con=null;
//参数信息
private Properties prop=null;
public MainApp()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
showSplashScreen();
}
});
try
{
Thread.sleep(2000);
}
catch(Exception e)
{
System.out.print(e);
}
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
hideSplashScreen();
}
});

this.setTitle("学生成绩管理系统");
contentPane=this.getContentPane();
//创建菜单
constructMenu();
//创建状态条
constructStatusPanel();
//读入系统参数
prop=SqlUtil.loadProperty("config/config.properties");
//建立数据库连接
connectToDB();

//添加导航面板
if(con!=null)
setSelectedPanel(new NavigatorPanel(this));
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
hideSplashScreen();
}
});
}
//连接到数据库
public void connectToDB()
{
try{
con=SqlUtil.acquireConnection(prop.getProperty("DB_IP"),
prop.getProperty("DB_PORT"),
prop.getProperty("DB_NAME"),
prop.getProperty("DB_USER_NAME"),
prop.getProperty("DB_USER_PWD"));
}
catch(Exception e)
{
con=null;
this.labStatusContent.setText("不能连接到数据库!"+
"请修改系统设置后重新启动该程序. "
+e.toString());
return;
}
}
public void showSplashScreen()
{
//取得屏幕大小
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
ImageIcon image=null;
try
{
image=new ImageIcon("image/splash.jpg");
}
catch(Exception e)
{
System.out.println(e);
}
JLabel splashLabel = new JLabel(image);
splashScreen = new JFrame();
//去掉JFrame的装饰边框
splashScreen.setUndecorated(true);
splashScreen.getContentPane().add(splashLabel);
splashScreen.pack();
int width=image.getImage().getWidth(null);
int height=image.getImage().getHeight(null);
//快闪屏幕居中
splashScreen.setLocation(new Point(((int)d.getWidth()-width)/2,
((int)d.getHeight()-height)/2));
splashScreen.setVisible(true);
}
public void hideSplashScreen()
{
splashScreen.setVisible(false);
splashScreen=null;
}

public void constructMenu()
{
//构建菜单
JMenuBar menuBar=new JMenuBar();

StudentResultM.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
MainApp.this.setSelectedPanel(new DBSFPanel(MainApp.this,con));
}
});
MMenu.add(StudentResultM);
menuBar.add(MMenu);

SysConfig.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
new ConfigDialog(MainApp.this).setVisible(true);
}
});
SetMenu.add(SysConfig);
menuBar.add(SetMenu);

aboutMe.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
new About().setVisible(true);
}
});

HelpMenu.add(aboutMe);
menuBar.add(HelpMenu);

setJMenuBar(menuBar);
}
//创建状态条
public void constructStatusPanel()
{
JPanel statusPanel=new JPanel();
Border loweredBevelBorder=BorderFactory.createLoweredBevelBorder();
statusPanel.setLayout(new GridBagLayout());
JLabel labStatus=new JLabel(" 提示信息 ");
labStatusContent=new JLabel();
JLabel labUser=new JLabel(" 用户名 ");
labUserContent=new JLabel();
labUserContent.setPreferredSize(new Dimension(90,3));
labUser.setBorder(loweredBevelBorder);
labUserContent.setBorder(loweredBevelBorder);
labStatus.setBorder(loweredBevelBorder);
labStatusContent.setBorder(loweredBevelBorder);
LayoutUtil.add(statusPanel,GridBagConstraints.NONE,
GridBagConstraints.CENTER,0,0,0,0,1,1,labStatus);
LayoutUtil.add(statusPanel,GridBagConstraints.BOTH,
GridBagConstraints.CENTER,100,100,1,0,1,1,labStatusContent);
LayoutUtil.add(statusPanel,GridBagConstraints.NONE,
GridBagConstraints.CENTER,0,0,2,0,1,1,labUser);
LayoutUtil.add(statusPanel,GridBagConstraints.VERTICAL,
GridBagConstraints.CENTER,0,100,3,0,1,1,labUserContent);
contentPane.add(statusPanel,BorderLayout.SOUTH);
}
public void setSelectedPanel(JPanel p)
{
if(selectedPanel!=null)
contentPane.remove(selectedPanel);
selectedPanel=p;
contentPane.add(selectedPanel,"Center");
this.validate();
}

public static void main(String []args)
{
MainApp ma=new MainApp();
ma.setDefaultCloseOperation(EXIT_ON_CLOSE);
ma.setSize(600,400); //设置主画面初始大小
ma.setVisible(true);
}
}

----------------解决方案--------------------------------------------------------

执行的时候要加上驱动类


----------------解决方案--------------------------------------------------------
  相关解决方案