java資料庫表
首先,數據表存不存在這是屬於資料庫的范疇,跟java沒有必然聯系,你說的java或者jdbc來判斷,最終也是調用的sql語句來判斷的。
判斷數據表存不存在是用sql語句來判斷的,不同的資料庫,其判斷的方式有些不一樣,
比如oralce、mysql資料庫 你可以用create table if not exists 這個語法句式來創建表。
2. 如何利用java輸出一個資料庫表的內容
主要的幾個點:
1、確定表有多少行。
2、按表的行數畫表格。
給你個示列
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
3. java如何獲取資料庫中所有表名
有多種方法的,最簡單的就是直接用sql查詢(比如mysql是:show tables),然後java裡面用一個map接收就好了。也可以通過java對資料庫的鏈接來直接獲取資料庫表名的。
4. java 怎樣取出資料庫的表
假設資料庫中的表是table ,表中的欄位對應 Student類欄位
代碼:
ArrayList<Student> list = null;//集合
Class.forName("org.sqlite.JDBC");//載入資料庫驅動
Connection conn = DriverManager.getConnection("jdbc:sqlite:sms.s3db");//鏈接資料庫,sms.s3db是資料庫名字,我用的是sqlite.
PreparedStatement ps = conn.PreparedStatement("select * from table");//創建語句對象
ResultSet rs = ps.executeQuery();//執行查詢
if(rs.next()){
Student stu=null;
stu = new Student(rs.getSting(1),rs.getString(2),。。。);
list.add(stu);
}
//輸出信息就行了,
Iterator<Student> it = null; //創建迭代器
while(it.hasNext()){
Student stu = it.next();
System.out.println(stu.toString);
}
.這樣就可以了。。。累死我了。希望你能成功。
不明白的追問我就ok
5. 如何用JAVA 創建資料庫表寫出java代碼
Connection conn = 鏈接
Statement stmt = conn.createStatementI();
String sql = "CREATE TABLE PFO_ANALYSE_BRANCH ( "
+" NODE_NAME_S VARCHAR2(50 BYTE), "
+ 其他欄位
+")";
stmt.execute(sql)
6. java中往資料庫表中添加data數據
只能寫個大概的,要寫數據到資料庫中,先得在資料庫中建庫,庫里建表,表裡建欄位,然後java里建立資料庫連接,用SQL語言寫數據到表中的欄位
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
//String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=資料庫名"; //7.0、2000
String url="jdbc:sqlserver://localhost:1433;DatabaseName=資料庫名"; //2005
Connection conn=null;
conn= DriverManager.getConnection(url,用戶名,密碼);
PreparedStatement pst=null;
pst=conn.prepareStatement("Insert Into grade(表名) Values (?)");
pst.setInt(1,你要寫的整弄數據);
//pst.setString(2,你要寫的字元串數據);
pst.addBatch();
pst.executeBatch();
7. 在java中怎麼創建資料庫和資料庫表
?????正常不會在java中進行創建資料庫和數據表,只會對資料庫進行操作;
資料庫的建立需要數據開發工具(SQL
server2005或者其他的)來設計;