jdbc.java
package wu;
import java.sql.*;
public class jdbc {
public jdbc() {
}
Connection conn = null ;
String re = "" ;
//设置你的数据库ip
String dbip = "127.0.0.1" ;
//设置你的数据库用户名和密码:
String use = "root" ;
String pass = "" ;
public java.sql.Connection getConn(){
try{
//Class.forName("org.gjt.mm.mysql.Driver").newInstance();
//String url ="jdbc:mysql://"+dbip+":3306/lyb"+use+"?user="+use+"&password="+pass+"&useUnicode=true&characterEncoding=gb2312" ;
//conn= DriverManager.getConnection(url);
Class.forName("org.gjt.mm.mysql.Driver");
//String url ="jdbc:mysql://localhost:3306/lyb"
conn= DriverManager.getConnection("jdbc:mysql://localhost/lyb","root","");
}
catch (Exception ex){
}
return this.conn ;
}
public String ex_chinese(String str){
if(str==null){
str ="" ;
}
else{
try {
str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
}
catch (Exception ex) {
}
}
return str ;
}
public String gettime() {
String datestr = "" ;
try {
java.text.DateFormat df = new java.text.SimpleDateFormat("yyyy年MM月dd日 HH点ss分") ;
java.util.Date date = new java.util.Date() ;
datestr = df.format(new java.util.Date()) ;
}
catch (Exception ex) {
}
return datestr ;
}
}
CREATE database lyb;
CREATE TABLE liuyan_temp (
id int(6) NOT NULL auto_increment,
url varchar(100) default '#',
ip varchar(20) default NULL,
email varchar(50) default '#',
qq varchar(20) default NULL,
sj varchar(30) default NULL,
content text,
xm varchar(20) default '没有姓名',
KEY id (id)
) TYPE=MyISAM;
本文地址:http://com.8s8s.com/it/it11984.htm