|
package jj.chen;
//第一次用derby,感觉上小巧灵活,呵呵
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Testdb implements Serializable{
/**
*
*/
private static final long serialVersionUID = 8351691821437574002L;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
String url="jdbc:derby:jjtest;create=true";//create=true 如果数据库不存在就自动创建
String user="myuser";
//随便填
String password="mypassword";//随便填
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt = conn.createStatement();
stmt.execute("create table table1(aaa varchar(30),bbb varchar(70),ccc varchar(75))");
stmt.execute("insert into table1 (aaa,bbb,ccc) values('11111','222','ccccccc')");
ResultSet rs =stmt.executeQuery("select * from table1");
while (rs.next()){
System.out.println(rs.getString("aaa"));
}
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
|