/**
* mysql连接数据库
* 当然首先得配置好驱动程序,保证程序可以正常操作数据库
* 驱动程序下载地址: http://mysql.ntu.edu.tw/Downloads/Connector-J/mysql-connector-java-5.0.6.zip
*/
import java.sql.*;
public class Test4 {
public Connection getConn()
{
Connection C=null;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
C= DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=admin&useUnicode=true&characterEncoding=8859_1");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return C;
}
public static void main(String[] arg)
{
Test4 test=new Test4();
Connection conn=test.getConn();
try {
Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
st.execute("insert into test values(2,'FLB2',25)");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(conn!=null)
{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.exit(0);
}
}
* mysql连接数据库
* 当然首先得配置好驱动程序,保证程序可以正常操作数据库
* 驱动程序下载地址: http://mysql.ntu.edu.tw/Downloads/Connector-J/mysql-connector-java-5.0.6.zip
*/
import java.sql.*;
public class Test4 {
public Connection getConn()
{
Connection C=null;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
C= DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=admin&useUnicode=true&characterEncoding=8859_1");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return C;
}
public static void main(String[] arg)
{
Test4 test=new Test4();
Connection conn=test.getConn();
try {
Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
st.execute("insert into test values(2,'FLB2',25)");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
if(conn!=null)
{
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
System.exit(0);
}
}