大家好~
在這裡想請教大家一個問題...
我想要撰寫一個程式,敘述如下:
我已經用Access建立了一個物料明細的資料庫,內容包括:物料編號,數量,入庫日期,儲存架編號,儲存倉編號.(需要資料庫可以寫信給我)
我想用Java寫出~
1.首先顯示我想變動(數量增加或減少)的該項物料明細
2.記錄目前的時間,並將時間寫入資料庫(開始時間)的欄中記錄下來
3.開始物料的運算(增加或減少)
4.紀錄運算結束的時間,並將時間寫入資料庫(結束時間)的欄中記錄下來
5.顯示該項物料變動後的明細(數量)
ps.欲變動的物料以及增減的數量可以用隨機的方式來指定
拜託會寫程式的知識好手們可以幫幫忙寫個簡單的範例讓我參考,拜託你們了~(雙手奉上20點)
2007-02-20 22:00:59 · 1 個解答 · 發問者 袋鼠 1 in 電腦與網際網路 ➔ 程式設計
謝謝Ted Wang所提供的方法~
但這程式碼是能顯示我資料庫某一欄位的Top 10資料,
跟我描述的有些差距,希望大家能幫忙
謝謝~
2007-02-21 20:02:45 · update #1
import java.sql.*;
import java.sql.SQLException;
import java.sql.ResultSet;
public class access
{
public static void main(String[] args)
{
try
{
ResultSet rs = null;
Connection conn = null;
Statement stat = null;
String strSql = "";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ= c:/test.mdb;DriverID=22;READONLY=true}";
conn = DriverManager.getConnection(database ,"","");
stat = conn.createStatement();
try
{
strSql = "select top 10 * from 資料表單名稱";
rs = stat.executeQuery(strSql);
while (rs.next()){
System.out.println(rs.getString("欄位名稱"));
}
}
catch(SQLException e)
{
System.out.println(e);
}
catch(NullPointerException e)
{
System.out.println(e);
}
catch(Exception e)
{
System.out.println(e);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
2007-02-21 10:02:51 補充:
將"改成雙引號
2007-02-27 12:09:41 補充:
strSql = "select * from 物料 where 物料編號 = '物料號碼'";
rs = stat.executeQuery(strSql);
while (rs.next()){
System.out.println(rs.getString("物料編號"));
2007-02-27 12:09:44 補充:
System.out.println(rs.getString("料架編號"));
System.out.println(rs.getString(儲存倉編號,入庫日期"));
System.out.println(rs.getString("數量"));
System.out.println(rs.getString("入庫日期"));
}
2007-02-27 23:45:20 補充:
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.DecimalFormat;
import java.text.NumberFormat;
2007-02-27 23:45:34 補充:
public class DateDemo {
public static void main(String[] args) {
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println(dateFormat.format(date));
2007-02-27 23:45:50 補充:
DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(dateFormat1.format(date));
2007-02-27 23:46:13 補充:
NumberFormat formatter = new DecimalFormat("######.##");
String s = formatter.format(1234.567); // 001234.567
System.out.println(s);
2007-02-27 23:46:23 補充:
NumberFormat formatter1 = new DecimalFormat("######");
String s1 = formatter1.format(25.0); // 25
System.out.println(s1);
}
}
2007-02-28 22:56:26 補充:
import java.sql.*;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
2007-02-28 22:56:42 補充:
public class access {
public static void main(String[] args) {
try {
ResultSet rs = null;
Connection conn = null;
Statement stat = null;
String strSql = "";
2007-02-28 22:56:52 補充:
NumberFormat formatter = new DecimalFormat("######.##");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ= c:/stocks.mdb;DriverID=22;READONLY=true}";
2007-02-28 22:57:02 補充:
conn = DriverManager.getConnection(database ,"","");
stat = conn.createStatement();
2007-02-28 22:57:18 補充:
try {
//strSql = "select top 10 * from 物料明細";
strSql = "SELECT * FROM 物料明細 WHERE 物料編號 between '500' and '515'";
rs = stat.executeQuery(strSql);
2007-02-28 22:57:29 補充:
System.out.println("編號" "\t" "數量" "\t" "料架碼" "\t" "倉碼" "\t" "入庫日期");
System.out.println("=====" "\t" "======" "\t" "======" "\t" "=====" "\t" "========");
while (rs.next()){
2007-02-28 22:57:44 補充:
String dbmydate = rs.getString("入庫日期");
Date mydate = new Date(Integer.valueOf(dbmydate.substring(0,4)).intValue()-1900,Integer.valueOf(dbmydate.substring(5,7)).intValue()-1,Integer.valueOf(dbmydate.substring(8,10)).intValue());
2007-02-28 22:57:52 補充:
System.out.println(rs.getString("物料編號") "\t" formatter.format(Float.valueOf(rs.getString("數量")).floatValue()) "\t" rs.getString("料架編號") "\t" rs.getString("儲存倉編號") "\t" dateFormat.format(mydate));
}
2007-02-28 22:58:04 補充:
} catch(SQLException e) {
System.out.println(e);
} catch(NullPointerException e) {
System.out.println(e);
}
2007-02-28 22:58:13 補充:
}catch(Exception e){
System.out.println(e);
}
}
}
2007-02-21 05:02:26 · answer #1 · answered by 醉愛翡翠珠寶精品 3 · 0⤊ 0⤋