THE THIRTY-SECOND DAY

    今天星期一,参加培训的第三十二天,与昨天一样,但是起的晚了些,在宿舍看了一会书,然后去吃饭了,来到教室,继续看书,什么格式化了,numberformat,dateformat 了,然后就没有什么了,其实的确也没有什么了,老师继续讲他的数据库,说什么,preparestatement 很重要,也没有什么,就是?罢了。

    然后别的什么也不想说,开始贴代码吧:

    鼠标右击事件:

package pm;

import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JPopupMenu;

public class Button3_Mask extends JFrame{
	public void contentPane_mouseClicked(MouseEvent e) {
		JPopupMenu jPopupMenu1 = new JPopupMenu();
        this.add(jPopupMenu1);
        int mods = e.getModifiers();
//鼠标右键
        if ((mods & InputEvent.BUTTON3_MASK) != 0) {
            //弹出菜单
            jPopupMenu1.show(this, e.getX(), e.getY());
        }
    }
//BUTTON1_MASK)鼠标左键
//BUTTON2_MASK)滚周
//BUTTON3_MASK)鼠标右键
}

从properties读取数据:

package pm;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.Properties;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

public class ReadProp {

	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
          read1();
	}
	public static void read1() throws Exception {
		System.out.println(ReadProp.class.getResource(""));
		
		String str = "d:";//绝对路径
		InputStream in = new BufferedInputStream(new FileInputStream("name"));
		Properties p = new Properties();
		p.load(in);
		String s = p.getProperty("key").toString();
		s= new String(s.getBytes("ISO-8859-1"), "UTF-8");
		System.out.println(s);
		in.close();
	}
	public static void read2() throws UnsupportedEncodingException {//常用
		ResourceBundle rb = ResourceBundle.getBundle("180409.pm.jdbc");
		Properties p = new Properties();
		Enumeration<String> e = rb.getKeys();
		while(e.hasMoreElements()) {
			String o = e.nextElement();
			p.put(o, rb.getObject(o));
		}
		String s = p.getProperty("tt").toString();
		s= new String(s.getBytes("ISO-8859-1"), "UTF-8");
		System.out.println(s);
	}
	public static void read3() throws Exception {
		String str = "d:";//绝对路径
		InputStream in = new BufferedInputStream(new FileInputStream("name"));
	    ResourceBundle rb = new PropertyResourceBundle(in);
	    Properties p = new Properties();
		Enumeration<String> e = rb.getKeys();
		while(e.hasMoreElements()) {
			String o = e.nextElement();
			p.put(o, rb.getObject(o));
		}
		String s = p.getProperty("tt").toString();
		s= new String(s.getBytes("ISO-8859-1"), "UTF-8");
		System.out.println(s);
	}
	public static void read4() throws Exception {
		String name = "./jdbc.properties";
		InputStream in = ReadProp.class.getResourceAsStream(name);
		Properties p = new Properties();
		p.load(in);
		String s = p.getProperty("key").toString();
		s= new String(s.getBytes("ISO-8859-1"), "UTF-8");
		System.out.println(s);
		in.close();
	}
	public static void read5() throws Exception {
		String name = "./180409/pm/jdbc.properties";//相对于classloader
		InputStream in = ReadProp.class.getClassLoader().getResourceAsStream(name);
		Properties p = new Properties();
		p.load(in);
		String s = p.getProperty("key").toString();
		s= new String(s.getBytes("ISO-8859-1"), "UTF-8");
		System.out.println(s);
		in.close();
	}
	public static void read6() throws Exception {//常用
		String name = "./180409/pm/jdbc.properties";//相对于classloader
		InputStream in = ClassLoader.getSystemResourceAsStream(name);
		Properties p = new Properties();
		p.load(in);
		String s = p.getProperty("key").toString();
		s= new String(s.getBytes("ISO-8859-1"), "UTF-8");
		System.out.println(s);
		in.close();
	}

}

jdbcutil:

package pm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;

public class JDBCUtil {
//	private static String DRIVER = "com.mysql.jdbc.Driver";
//	private static String URL = "jdbc:mysql://127.0.0.1:3306/180408work";
//	private static String USER = "root";
//	private static String PASSWORD = "lizean";

	private final static String DRIVER;
	private final static String URL;
	private final static String USER;
	private final static String PASSWORD;
	private JDBCUtil() {

	}

	static {
		ResourceBundle rb = ResourceBundle.getBundle("180409.pm.jdbc");
		DRIVER = rb.getString("driver");
		URL = rb.getString("url");
		USER = rb.getString("user");
		PASSWORD = rb.getString("pass");
		try {
			Class.forName(DRIVER);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	private static Connection getConnection() throws Exception {
		// DriverManager.registerDriver(new com.mysql.jdbc.Driver());
		return DriverManager.getConnection(URL, USER, PASSWORD);
	}

	public static Statement getStatement() throws Exception {
		return getConnection().createStatement();
	}

	public static void close(Connection conn, Statement st, ResultSet resultSet) {
		try {
			if (resultSet != null) {
				resultSet.close();
			}
			if (st != null) {
				st.close();
			}
			if (conn != null) {
				conn.close();
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
然后没有什么东西了,行吧,也不想写些什么了,就这样吧,结束。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值