[java理论篇]--java的其他常用API
1、java的正則表達式:
? ? ?常用方法:String ?matches(匹配) ?;
? ? ? ? ? ? ? ? ? ? ? ?String ?split(切割);
? ? ? ? ? ? ? ? ? ? ? ?String replaceAll(替換);
? ? ? ? ? ? ? ? ?利用正則表達式獲取字符創的核心代碼:
? ? String str=“dsadasd”;
? ? String reg="相應的正則表示式";
? ? Pattern p = Pattern.compile(reg);
? ?Marcher m= p.matcher(str);
? ? m.matches();
2、JDBC
package hello.ant;
import java.sql.*;
public class jdbc
{
String dbUrl="jdbc:oracle:thin:@127.0.0.1:1521:orcl";
String theUser="admin";
String thePw="manager";
Connection c=null;
Statement conn;
ResultSet rs=null;
public jdbc()
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
c = DriverManager.getConnection(dbUrl,theUser,thePw);
conn=c.createStatement();
}catch(Exception e){
e.printStackTrace();
}
}
public boolean executeUpdate(String sql)
{
try
{
conn.executeUpdate(sql);
return true;
}
catch (SQLException e)
{
e.printStackTrace();
return false;
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
rs=conn.executeQuery(sql);
}
catch (SQLException e)
{
e.printStackTrace();
}
return rs;
}
public void close()
{
try
{
conn.close();
c.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
ResultSet rs;
jdbc conn = new jdbc();
rs=conn.executeQuery("select * from test");
try{
while (rs.next())
{
System.out.println(rs.getString("id"));
System.out.println(rs.getString("name"));
}
}catch(Exception e)
{
e.printStackTrace();
}
}
}
轉載于:https://blog.51cto.com/seasky09/1251375
總結
以上是生活随笔為你收集整理的[java理论篇]--java的其他常用API的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C Primer+Plus(十七)高级数
- 下一篇: 电脑公司 Ghost XP SP3 国庆