java 怎麼獲取硬碟序列號

	
publicstaticvoidmain(String[]args){

StringHDserialnumber=getHdSerialInfo();
System.out.println(HDserialnumber);
}

(){

Stringline="";

StringHdSerial="";//定義變數硬碟序列號
try{
Processproces=Runtime.getRuntime().exec("cmd/cdirc:");//獲取命令行參數
BufferedReaderbuffreader=newBufferedReader(newInputStreamReader(proces.getInputStream()));
while((line=buffreader.readLine())!=null){
if(line.indexOf("卷的序列號是")!=-1){//讀取參數並獲取硬碟序列號
HdSerial=line.substring(line.indexOf("卷的序列號是")+"卷的序列號是".length(),line.length());
break;
}
}
}catch(IOExceptione){
e.printStackTrace();
}
returnHdSerial;//返回硬碟序列號卷的序列非物理

}

㈡ java 能不能獲取CPU的ID號,硬碟的序列號

///==============================獲取序列號========
package com.test;
import java.io.IOException;
import java.util.Scanner;

public class CpuUtil {
public static void main(String[] args) throws IOException {
long start = System.currentTimeMillis();
Process process = Runtime.getRuntime().exec(
new String[] { "wmic", "cpu", "get", "ProcessorId" });
process.getOutputStream().close();
Scanner sc = new Scanner(process.getInputStream());
String property = sc.next();
String serial = sc.next();
System.out.println(property + ": " + serial);
System.out.println("time:" + (System.currentTimeMillis() - start));
}
}

//=======================獲取硬碟序列號==========================
package com.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class DiskUtil {
public static String getSerialNumber(String drive) {
String result = "";
try {
File file = File.createTempFile("realhowto",".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\n"
+"Set colDrives = objFSO.Drives\n"
+"Set objDrive = colDrives.item(\"" + drive + "\")\n"
+"Wscript.Echo objDrive.SerialNumber"; // see note
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
}
catch(Exception e){
e.printStackTrace();
}
return result.trim();
}
public static void main(String[] args) {
String sn = DiskUtil.getSerialNumber("C");
System.out.println(sn);
}

//=============================獲取主板序列號====================
package com.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class MiscUtil {
public static String getMotherboardSN() {
String result = "";
try {
File file = File.createTempFile("realhowto", ".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+ "Set colItems = objWMIService.ExecQuery _ \n"
+ " (\"Select * from Win32_BaseBoard\") \n"
+ "For Each objItem in colItems \n"
+ " Wscript.Echo objItem.SerialNumber \n"
+ " exit for ' do the first cpu only! \n" + "Next \n";
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec(
"cscript //NoLogo " + file.getPath());
BufferedReader input = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
} catch (Exception e) {
e.printStackTrace();
}
return result.trim();
}
public static void main(String[] args) {
String cpuId = MiscUtil.getMotherboardSN();
System.out.println(cpuId);

}
}

㈢ java中如何設計一個由3個段數值組成的序列號

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

class Example6_14 extends JFrame implements KeyListener

{

JTextField t[]=new JTextField[4];

Example6_14()

{

setTitle("序列號輸入程序");

setSize(400,300);

setVisible(true);

setLayout(new FlowLayout());

for(int i=1;i<=3;i++)

{

t[i]=new JTextField(10);

add(t[i]);

t[i].addKeyListener(this);

}

add(new JButton("下一步"));

setDefaultCloseOperation(EXIT_ON_CLOSE);

validate();

}

public void keyPressed(KeyEvent e)

{

if(t[1].getText().length()==4)

t[1].transferFocus();

else if(t[2].getText().length()==4)

t[2].transferFocus();

else if(t[3].getText().length()==4)

t[1].setText("序列號正在處理中");

}

public void keyReleased(KeyEvent e){}

public void keyTyped(KeyEvent e){}

public static void main(String[] args)

{

new Example6_14();

}

}

㈣ 如何用java取得在oracle後台取得的sequence的序號的相關推薦

您好,很高興為您解答。

publicclassSeqManager{
protectedStringdataSource="java:/OracleDS";
publicSeqManager(){
}
/**
*從資料庫連接中取的一連接
*
*@paramStringdataSource為數據源JNDI
*
*
*返回值為資料庫連接
*
*/
(StringdataSource)
{
Connectioncon=null;
try
{
InitialContextic=newInitialContext();
DataSourceds=(DataSource)ic.lookup(dataSource);
con=ds.getConnection();
System.out.println("connectionis:"+con);
//con.setAutoCommit(false);
}catch(NamingExceptione)
{
Stringerr="連接資料庫時出錯:找不到JNDI名稱"+dataSource;
System.out.println(e);
e.printStackTrace();
}catch(SQLExceptionex)
{
Stringerr="連接資料庫時出錯:創建不了資料庫連接";
System.out.println(ex);
ex.printStackTrace();
}
returncon;
}
/**
*取Sequence的公共方法
*
*@paramStringsql為傳進的SQL語句
*
*
*返回值為Sequence值
*
*/
protectedLonggetNextValOfSeq(Stringsql)throwsSQLException
{
Connectioncon=getConnection(dataSource);
PreparedStatementpst=con.prepareStatement(sql);
ResultSetrs=pst.executeQuery();
try
{
if(rs.next()){
returnnewLong(rs.getLong(1));
}
else{
returnnull;
}
}catch(SQLExceptione)
{
throwe;
}finally
{
rs.close();
pst.close();
con.close();
}
}
()throwsSQLException
{
Stringsql="SelectSeqStudEntrScore.NextValFromDual";
try
{
returngetNextValOfSeq(sql);
}catch(SQLExceptione)
{
StringerrorMessage="取***Sequence時出錯.";
e.printStackTrace();
thrownewSQLException(errorMessage);
}
}
}



在jsp里調用這個javaBean
jsp就是一個servlet
操作資料庫沒什麼區別


如若滿意,請點擊右側【點贊答案】,如若還有問題,請點擊【追問】


希望我的回答對您有所幫助,望點贊!


~O(∩_∩)O~

㈤ java自動生成的序列號

添加前進頁面的時候就把資料庫中最大的那個序列號拿出來,加上1在頁面顯示,然後傳道後台保存,修改的話到資料庫驗證下序列號,存在的話就不給保存。

㈥ 求java自動生成一個序列號的方法,急急急...

package com.test4;

public class Test7 {
public static void main(String[] args) {
System.out.println(getNum("20100505",3));
}

//假設來資料庫里源有個20100505005的編號
private static String getNum(String firstPart, int len) {
//調用資料庫獲得20100505005這個編號
String oldNum = "20100505005";
int num = Integer.parseInt(oldNum.replace(firstPart,""));
String numStr = ++num +"";
int length = numStr.length();
for (int i = length; i < len; i++) {
numStr = "0"+numStr;
}
return firstPart + numStr;
}
}

㈦ JAVA 編程 序列號

//哎....

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import javax.swing.*;
import javax.swing.text.MaskFormatter;

public class CodeTest extends JFrame {
private static final long serialVersionUID = 1L;
private JFormattedTextField formatField = null;
private JButton ba = null;
private String pattern = "AAAAA-AAAAA-AAAAA-AAAAA";
private JLabel code = new JLabel("注冊碼: ");
private JLabel input = new JLabel("序列號: ");
private JTextField codeField = new JTextField();
private JLabel rel = new JLabel();

public CodeTest(){
init();
}

public void init(){
MaskFormatter mft = CodeTest.getFormatter(pattern);
mft.setPlaceholderCharacter('X');
formatField = new JFormattedTextField();
formatField = new JFormattedTextField();
mft.install(formatField);
this.setBounds(200, 200, 240, 240);
this.setResizable(false);
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
formatField.setBounds(30, 30, 180, 25);
ba = new JButton("注冊");
ba.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(formatField.getText().length() >= 1) {

}
String text = formatField.getText();
long vlong = getCode(text);
code.setText("注冊碼: (" + vlong + ")");
if((vlong + "").equals(codeField.getText())){
rel.setText("注冊成功!");
System.exit(0);
} else {
rel.setText("注冊失敗!");
}
}
});
codeField.setBounds(30, 85, 180, 25);
code.setBounds(30, 60, 180, 25);
ba.setBounds(30, 125, 180, 25);
rel.setBounds(30, 155, 100, 25);
input.setForeground(Color.RED);
code.setForeground(Color.RED);
rel.setForeground(Color.RED);
input.setBounds(30, 5, 100, 25);
this.add(rel);
this.add(codeField);
this.add(input);
this.add(code);
this.add(ba);
this.add(formatField);
ba.setDefaultCapable(true);

this.setVisible(true);
}

public static void main(String[] args) {
new CodeTest();

}

public static MaskFormatter getFormatter(String pattern){
try {
return new MaskFormatter(pattern);
} catch (ParseException e) {
e.printStackTrace();
return null;
}
}

public long getCode(String text){
char [] chs = text.toCharArray();
long vlong = 0;
for(char c: chs){
if(c != '-'){
vlong += 199 * (int)c;
}
}
return vlong;
}

}

㈧ java中 如何實現這樣規則的序列號

Oracle的話,用SEQUENCE,如果是JAVA的話,用一個變數來保存就好。

寫個方法,下面只是演示,代回碼只是演示代答碼,實際根據自己情況自己補充:
public String getOrderNo(Date d) {
if (d == null) {
d = new Date();
}
String dOut = doFormat(d);// 自己寫個處理函數處理日期到上面你說的格式。
Int lastNo = getLastNumberFromConfigFile(dOut);//自己寫一個從配置文件里讀取上面日期的函數,如果沒有就返回0
lastNo ++;
setlastNumberToConfiFile(dOut, lastNo);
String sOut = dOut + (lastNo / 1000).subString(3, 3); //
return sOut;
}

如果是J2ee里是單線程操作的話,可以這樣,如果可能會多線程操作,要加上synchronized或加LOCK來處理。