?? jdbctest.java
字號:
import java.sql.*;
import demo.NoticeBean;
public class JdbcTest {
public static void main(String[] args) {
Connection conn=null;
Statement st=null;
ResultSet rs=null;
try{
String dirvername="org.gjt.mm.mysql.Driver";
Class.forName(dirvername);
String url="jdbc:mysql://localhost:3306/myproject?useUnicode=true&character Encoding=gb2312";
conn=DriverManager.getConnection(url,"root","102386");
System.out.println("連接數(shù)據(jù)庫成功!");
String title="xue";
String fileRecord="中國";
String content=new String(fileRecord.getBytes("gb2312"),"ISO-8859-1");
String strSql="insert into notice(title,content) values('"+title+"','"+content+"')";
st=conn.createStatement();
st.executeUpdate(strSql);
System.out.println("插入成功!");
String strSql2="select * from notice";
rs=st.executeQuery(strSql2);
while(rs.next()){
System.out.println("ID="+rs.getInt("id"));
System.out.println("title="+rs.getString("title"));
fileRecord=rs.getString("content");
System.out.println("content="+new String(fileRecord.getBytes("ISO-8859-1"),"gb2312"));
}
String strSql3="delete from notice";
//st.executeUpdate(strSql3);
//System.out.println("刪除成功!");
}
catch(Exception e)
{
System.out.print(e.getStackTrace());
}
finally{
try{
if(rs!=null){
rs.close();
rs=null;
}
if(st!=null){
st.close();
st=null;
}
if(conn!=null){
conn.close();
conn=null;
}
}catch(Exception e){}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -