序列号java
㈠ 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来处理。