JAVAµ÷ÓÃMYSQL´æ´¢¹ý³Ì
JAVAµ÷ÓÃMYSQL´æ´¢¹ý³Ì
¹¤³ÌÊÓͼ£º
´úÂëÇåµ¥£º
myconn.java
package org.apache.sh_mysql.test;
import java.sql.*;
public class MyConn {
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=GBK";
private static final String USER = "root";
private static final String PASSWORD ="root";
static {
try {
Class.forName(DRIVER);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* »ñÈ¡Á¬½Ó
*
* @return
* @throws Exception
*/
public Connection getConnection() throws Exception {
return DriverManager.getConnection(URL, USER, PASSWORD);
}
/**
* ÊÍ·Å×ÊÔ´
*
* @param rs
* @param statement
* @param conn
*/
public void close(ResultSet rs, CallableStatement stmt, Connection conn) {
try{
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
´úÂëÇåµ¥£º
mytest.java
package org.apache.sh_mysql.test;
import java.sql.*;
public class MyTest {
MyConn c=new MyConn();
public void handleData() {
try {
Connection conn=c.getConnection();
CallableStatement call=conn.prepareCall("{call pro_stu_count(?)}");
call.registerOutParameter(1, Types.INTEGER);
call.execute();
int count=call.getInt(1);
System.out.println(count);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public static void main(String[] args) {
MyTest t=new MyTest();
t.handleData();
}
}
Ïà¹ØÎĵµ£º
2008-04-26 09:25 ×÷Õߣºsuperman À´Ô´£ºÈüµÏÍø
[ÕªÒª] Ê×ÏÈ£¬±¾ÎĵÄÄ¿±ê¶ÁÕßÊÇÕýÔÚ´Óʼ¼Êõ¹¤×÷µÄ¼Ü¹¹Ê¦¡£±ÜÃâ½²ÊöһЩ³Â¸¯µÄ×î¼Ñʵ¼ù£¬ÀýÈç"ÈÕ³£¹¹½¨£¨build daily£©"¡¢"²âÊÔÒ»ÇУ¨test everything£©"ºÍ"¾³£¼¯³É£¨ integrate often£©¡£ ÈκξßÓгÆÖ°¼Ü¹¹Ê¦µÄÏîÄ¿¶¼Óзֹ¤Ã÷È·µÄ¡¢¶¨ÒåÁ¼ºÃµÄÍŶӽṹ¡£ËûÃÇ»¹Îª½øÐбà ......
ÒÔÇ°¶¼ÊÇÓÃÒ»°ãµÄsocket±à³Ì£¬ÓÃÏß³ÌÀ´¿ØÖÆ¡£×î½üͻȻÓÃnioÀ´×öЩ¶«Î÷¡£
nioµÄºÃ´¦ÎÒÀ´ËµÒ»Ï£ºµÚÒ»£¬¶Áд¶¼ÊÇ»ùÓÚ¿éµÄ£¬Ð§Âʸߡ£µÚ¶þ£¬Í¨¹ýÒýÈëselector,¼ò»¯ÁËÍøÂç±à³ÌÄ£ÐÍ£¬Òì²½·Ç×èÈû¡£
¼ÈÈ»ÓÐÕâô¶àºÃ´¦£¬ÄǾÍд¸öNIO TCPÍøÂçÁÄÌìÊÒÀ´Á·Á·ÊÖ°É¡£
ÒòΪûÓÐдgui£¬ÊÇ»ùÓÚ¿ØÖÆ̨µÄËùÒÔûд˽Á˵IJ¿·Ö£¬Ö»Ð´Á˹«¹²ÁÄÌìÊ ......
·þÎñÆ÷ÖÐתÏûÏ¢£¬ÊÇ·ÑʱµÄÊ£¬¿ÉÒÔ¼ÓÈë¶àÏ̡߳£ÕâÑùÒÔÀ´£¬»á²úÉúºÜ¶àÏ̡߳£¿ÉÒÔÔËÓÃÏ̳߳ØÀ´¹ÜÀí¡£
ÕâÀïÔËÓÃjava.util.concurrent°üµÄExecutors.newCachedThreadPoolÀ´¹ÜÀí¡£
·Ï»°ÉÙ˵£¬ÉÏ´úÂ룺
·þÎñÆ÷¶Ë£ºMySocketServer.java
/*
* To change this template, choose Tools | Templates
* and open the ......