java access sql
JDBCÁ¬½ÓMySQL
¼ÓÔؼ°×¢²áJDBCÇý¶¯³ÌÐò
Class.forName("com.mysql.jdbc.Driver");
Class.forName("com.mysql.jdbc.Driver").newInstance();
JDBC URL ¶¨ÒåÇý¶¯³ÌÐòÓëÊý¾ÝÔ´Ö®¼äµÄÁ¬½Ó
±ê×¼Óï·¨£º
<protocol£¨Ö÷ҪͨѶÐÒ飩>:<subprotocol£¨´ÎҪͨѶÐÒ飬¼´Çý¶¯³ÌÐòÃû³Æ£©>:<data source identifier£¨Êý¾ÝÔ´£©>
MySQLµÄJDBC URL¸ñʽ£º
jdbc:mysql//[hostname][:port]/[dbname][?param1=value1][¶m2=value2]….
ʾÀý£ºjdbc:mysql://localhost:3306/sample_db?user=root&password=your_password
³£¼û²ÎÊý£º
user ̞
password ÃÜÂë
autoReconnect Áª»úʧ°Ü£¬ÊÇ·ñÖØÐÂÁª»ú£¨true/false£©
maxReconnect ³¢ÊÔÖØÐÂÁª»ú´ÎÊý
initialTimeout ³¢ÊÔÖØÐÂÁª»ú¼ä¸ô
maxRows ´«»Ø×î´óÐÐÊý
useUnicode ÊÇ·ñʹÓÃUnicode×ÖÌå±àÂ루true/false£©
characterEncoding ºÎÖÖ±àÂ루GB2312/UTF-8/…£©
relaxAutocommit ÊÇ·ñ×Ô¶¯Ìá½»£¨true/false£©
capitalizeTypeNames Êý¾Ý¶¨ÒåµÄÃû³ÆÒÔ´óд±íʾ
½¨Á¢Á¬½Ó¶ÔÏó
String url="jdbc:mysql://localhost:3306/sample_db?user=root&password=your_password";
Connection con = DriverManager.getConnection(url);
½¨Á¢SQL³ÂÊöʽ¶ÔÏó£¨Statement Object£©
Statement stmt = con.createStatement()£»
Ö´ÐÐSQLÓï¾ä
executeQuery()
String query = "select * from test";
ResultSet rs=stmt.executeQuery(query);
½á¹û¼¯ResultSet
while(rs.next())
{rs.getString(1);rs.getInt(2);}
executeUpdate()
String upd="insert into test (id,name) values(1001,xuzhaori)";
int con=stmt.executeUpdate(upd);
execute()
Ïà¹ØÎĵµ£º
import java.awt.image. * ;
import com.sun.image.codec.jpeg. * ;
public class poiReadDoc {
Image img = null;
int width = 0,height =0;
String destFile = "";
public void readImg(String fileName) throws IOException{
File _fil ......
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyÄêMMÔÂddÈÕ HH:mm:ss");
System.out.println(sdf.format(date));
SimpleDateFormat sdf2 = new SimpleDateFormat("MM");
System.out.println(sdf2.format(date));
Calendar c = Calendar.getInstance();
System.out.println(c.get(C ......
¡¡1. String.trim()
¡¡¡¡trim()ÊÇÈ¥µôÊ×β¿Õ¸ñ
¡¡¡¡2.str.replace(" ", ""); È¥µôËùÓпոñ£¬°üÀ¨Ê×β¡¢Öмä
¡¡String str = " hell o ";
¡¡¡¡String str2 = str.replaceAll(" ", "");
¡¡¡¡System.out.println(str2);
¡¡¡¡3.»òÕßreplaceAll(" +",""); È¥µôË ......
public class JavaPlus {
public static void main(String[] args) {
int x = 5;
x++;// x = x + 1;//ºó¼Ó¼Ó
System.out.println(x);
x--;// x = x - 1;//ºó¼õ¼õ
System.out.println(x);
++x;// x = x + 1;//Ç°¼Ó¼Ó
Sys ......
0
£®ÒýÑÔ
ÔÚChinaITLAB
µ¼Ê¦ÖƸ¨µ¼ÖУ¬±ÊÕß·¢ÏÖÎʵÃ×î¶àµÄÎÊÌâĪ¹ýÓÚ"
ÈçºÎѧϰ±à³Ì£¿Java
¸ÃÈçºÎѧϰ£¿"
¡£ÀàËƵÄÎÊÌâ»Ø´ð¶àÁË£¬ÄÑÃâ»á¸Ð¾õÑá·³£¬¾ÍÃÈÉúÁËдϱ¾ÎĵÄÏë·¨¡£µ½Ê±ºòÔÙÓÐÈËÎÊÆðÀàËƵÄÎÊÌ⣬ÎÒ¿ÉÒÔ¸æËßËû£¨Ëý£©£¬ÇëÄãÈ¥¿´¿´¡¶Java
ѧϰ֮·¡·¡£°Ý¶Á¹ý̨Íå²ÌѧïÞÏÈÉúµÄ¡¶Java
ҹδÃß¡·£¬ÓÐ ......