import java.sql.*;
import java.lang.*;
public class ch1
{
public static void main(String args[ ])
{
String driver ="org.gjt.mm.mysql.Driver";
String url ="jdbc:mysql://127.0.0.1:3306/jsptest";
String user ="hukn";
String password="hukn";
try
{
Class.forName(driver);
}
catch(Exception E)
{
System.out.print("无法加载驱动:"+driver);
}
try
{
Connection con=DriverManager.getConnection(url,user,password);
if(!con.isClosed())
System.out.println("打开数据库成功");
Statement smt=con.createStatement();
smt.executeUpdate("insert into test(name,adress) values(中国,成都)");
smt.close();
con.close();
}
catch(SQLException SE)
{
System.out.print("打开数据库失败");
}
}
}
|