⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendardb.java

📁 日程安排小软件,通过它可以实现对日程表的查询添加删除等各种操作.
💻 JAVA
字号:
/*
 * 创建日期 2007-1-13
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package database;

/**
 * @author Administrator
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
import java.sql.*;
import java.util.ListIterator;
import java.io.*;

import javax.swing.JOptionPane;

import ui.CalPanel;
import ui.MainFrame;
public class CalendarDb{
	private Connection con=null;
	static{
		try{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			System.out.println("Success loading JDBC-ODBC Bridge Driver..\n");
			
		}
		catch(Exception e){
		System.out.println("Error loading JDBC-ODBC Bridge Driver..\n");
		e.printStackTrace();
		}
	}
	
	public CalendarDb()
	{
		try {
			con=DriverManager.getConnection("jdbc:odbc:Calendar","","");
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		
	}
	
	public boolean CheckLogin(String username,String password)
	{
		String strSQL="select * from useInfor where 姓名='"+username+"' and 密码='"+password+"'";
		boolean CanGo=false;
		System.out.println(strSQL);
	
		try{
			System.out.println("Success eastablishing the connection..\n");
			Statement stmt=con.createStatement();
			ResultSet rs=stmt.executeQuery(strSQL);
		
			
			if(rs.next()){
		
			CanGo=true;
			}		
		}
				catch(Exception e){
					
					e.printStackTrace();
				}
				return CanGo;
	}

	public Cal GetCal(String username)
	{
		Cal c=null;
		String strSql="SELECT * FROM Calendar WHERE 姓名='"+username+"'";
		Statement stmt;
		try {
			stmt = con.createStatement();
			ResultSet rs=stmt.executeQuery(strSql);
			
		if(rs.next())
			{
				c= new Cal();
				c.setId(rs.getInt(1));
				c.setName(rs.getString(2));
				c.setStartTime(rs.getDate(3));
				c.setEndTime(rs.getDate(4));
				c.setTitle(rs.getString(5));
				c.setContent(rs.getString(6));
			} 
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return c;
	}
	
	public CalList GetCalList(String username)
	{
		CalList cl = new CalList();
		Cal c=null;
		String strSql="SELECT * FROM Calendar WHERE 姓名='"+username+"'";
		Statement stmt;
		try {
			stmt = con.createStatement();
			ResultSet rs=stmt.executeQuery(strSql);
			
		while(rs.next())
			{
				c= new Cal();
				c.setId(rs.getInt(1));
				c.setName(rs.getString(2));
				c.setStartTime(rs.getDate(3));
				c.setEndTime(rs.getDate(4));
				c.setTitle(rs.getString(5));
				c.setContent(rs.getString(6));
				cl.add(c);
			} 
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		return cl;	
	}
	
	
	public boolean UpdateCal(Cal c)
	{
		String strSql="update Calendar set 起始时间= '"+c.getStartTime()+"',事件名称='"+c.getTitle()+"' ,详细描述='"+c.getContent()+"'where 编号="+c.getId();
		System.out.println(strSql);
		Statement stmt;
		try {
			stmt = con.createStatement();
			int n=stmt.executeUpdate(strSql);
		    if(n==1){
		    	return true;
		    }		
			
		} catch (SQLException e) {
			// TODO 自动生成 catch 块
			e.printStackTrace();
		}
		
		return false;
	}

	public boolean InsertCal(Cal c)
	{
	
		String strSql="insert into Calendar values('"+c.getName()+"','"+c.getStartTime()+"','"+c.getEndTime()+"','"+c.getTitle()+"','"+c.getContent()+"')";
		System.out.println(strSql);
		Statement stmt;
		try {
			stmt = con.createStatement();
			int n=stmt.executeUpdate(strSql);
		    if(n==1){
		    	return true;
		}
		    }catch (SQLException e) {
			e.printStackTrace();
		}
		
		return false;
}
	
	public boolean DeleteCal(Cal c)
	{
	
		String strSql="delete from Calendar where 编号="+c.getId();
		System.out.println(strSql);
		Statement stmt;
		try {
			stmt = con.createStatement();
			int n=stmt.executeUpdate(strSql);
		    if(n==1){
		    	return true;
		}
		    }catch (SQLException e) {
			e.printStackTrace();
		}
		
		return false;
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -