java代碼添加新表 java如何往表格添加數(shù)據(jù)

請問用java代碼如何創(chuàng)建數(shù)據(jù)表

class.forname("oracle.jdbc.driver.OracleDriver");//加載數(shù)據(jù)庫驅動

成都創(chuàng)新互聯(lián)是一家專注于成都做網(wǎng)站、成都網(wǎng)站制作與策劃設計,滑縣網(wǎng)站建設哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設十余年,網(wǎng)設計領域的專業(yè)建站公司;建站業(yè)務涵蓋:滑縣等地區(qū)?;h做網(wǎng)站價格咨詢:18980820575

String url="jdbc:oracle:thin:@localhost:1521:db_name";

String sql="CREATE TABLE table(filed1 varchar2(2),filed2 varchar2(2))";

Connection conn=DriverManager.getConnection(url,"scott","tiger");//建立數(shù)據(jù)庫連接

if(!conn.isClose()){

Statement stmt = conn.createStatement();

stmt.executeUPDATE(sql); //建立一個表

}

oracle數(shù)據(jù)庫 怎么用java代碼把從一張表中查詢出來的日期時間插入另一張表中

日期格式應該是Timestamp類型,是因為你打印出來才會顯示最后的零的,直接查詢出來,再存入另一張表就OK,不用轉換

注:如果想打印出來的沒有最后的零,可以用

public static final SimpleDateFormat dtmFormat = new SimpleDateFormat(

"yyyy-MM-dd HH:mm:ss"); // 設置格式化類型

Time

Timestamp dtm = new Timestamp(System.currentTimeMillis()); // 當前時間

String dateStr = dtmFormat.format(dtm); // 把當前時間格式化

java中創(chuàng)建表格的代碼

動態(tài)創(chuàng)建表格,比如:str你從數(shù)據(jù)庫讀出列名,data數(shù)據(jù)集

這里的data是一個二維數(shù)組,

就像

{{學號:001,出生:09-01,成績99}

{學號:001,出生:09-01,成績99}

{學號:001,出生:09-01,成績99}}

生成表格

學號 出生日期 成績

001 09-01 99

001 09-01 98

001 09-01 99

JAVA嵌入數(shù)據(jù)庫:用java代碼實現(xiàn)像數(shù)據(jù)庫表中插入信息,怎么寫?

Java程序向數(shù)據(jù)庫中插入數(shù)據(jù),代碼如下:

//首先創(chuàng)建數(shù)據(jù)庫,(access,oracle,mysql,sqlsever)其中之一,其中access,sqlsever需要配置數(shù)據(jù)源(odbc);//然后再eclipse中創(chuàng)建類(ConnDb,Test,TestBean)ConnDb功能為連接數(shù)據(jù)庫,查詢,插入,刪除,修改數(shù)據(jù)的類,Test為含有main方法的測試類,TestBean為數(shù)據(jù)表中的字段屬性及set,get方法//以下是ConnDb代碼:package db;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.ArrayList;public class ConnDb {public Connection startConn(Connection conn){ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:數(shù)據(jù)庫","用戶名", "密碼"); } catch (Exception e) { System.out.println("連接數(shù)據(jù)庫時出現(xiàn)錯誤"); } return conn; } public ArrayList executeQuery(String sql){ Connection conn = null; Statement stmt = null; ResultSet rs = null; ArrayList list = new ArrayList(); try { conn = startConn(conn); stmt = conn.createStatement(); rs = stmt.executeQuery(sql);//sql為sql語句例如"select * from 表名",從main方法中傳進來,這里用的是ArrayList 類將查詢結果存儲起來 while(rs.next()){ TestBean tb = new TestBean(); tb.setTid(rs.getString("tid")); tb.setTname(rs.getString("tname")); tb.setTinfo(rs.getString("tinfo")); list.add(tb); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ closeConn(rs,stmt,conn); } return list; } public void executeUpdate(String sql){ Connection conn = null; Statement stmt = null; try { conn = startConn(conn); stmt = conn.createStatement(); stmt.executeUpdate(sql); } catch (SQLException e) { System.out.println("修改,插入或者刪除數(shù)據(jù)庫數(shù)據(jù)時發(fā)生錯誤!"); }finally{ closeConn(stmt,conn); } } public void closeConn(ResultSet rs,Statement stmt,Connection conn){ try { if(rs != null){ rs.close(); } if(stmt != null){ stmt.close(); } if(conn != null){ conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block System.out.println("關閉數(shù)據(jù)庫的時候發(fā)生錯誤!"); } } public void closeConn(Statement stmt,Connection conn){ try { if(stmt != null){ stmt.close(); } if(conn != null){ conn.close(); } } catch (SQLException e) { // TODO Auto-generated catch block System.out.println("關閉數(shù)據(jù)庫的時候發(fā)生錯誤!"); } }}

文章題目:java代碼添加新表 java如何往表格添加數(shù)據(jù)
瀏覽路徑:http://www.muchs.cn/article28/doggojp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、網(wǎng)站收錄小程序開發(fā)、移動網(wǎng)站建設手機網(wǎng)站建設、網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設