HI, my problem like this;
I want to use Java to pass the datavalue of expectedState from MYSQL database ,save it and pass to another file called State.java?
*********************************************************************
// State.java
package JDBC;
import JDBC.split.*;
public class State {
//private int startState;
private int expectedState;
public State( int theStateId, int theExpectedState)
super( );
this.expectedState = theExceptedState;
}
public class getExceptedState(){
return exceptedState;
} public static class setExceptedState(String theExceptedState private String expectedState)
{
this.exceptedState = theExceptedState;
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(exceptedState.getExceptedState);
}
}//TestMyssqlConnection.java***************************************************************************88888
package JDBC;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestFSMMyssqlConnection {
//public static final Object MidState = null;//by eclipse on May 14
public static String ExpectedState;// change by me on May15
public void getExpectedState(String ExpectedState){
this.ExpectedState = ExpectedState;
System.out.println("ExpectedState:"+ExpectedState);
} public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs1 = null;
//Object MidState = null;//added by eclipse
//String MidState ;
String ExpectedState;
//ResultSet rs2=null; try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager
.getConnection("jdbc:mysql://localhost/myfsmdata?user=root&password=root");
stmt = conn.createStatement();
rs1 = stmt.executeQuery("select TempState from fsm2 where stateid=0");// using transitons replace *
//rs2 = stmt.executeQuery("select TempState from fsm2 where stateid=0");
while (rs1.next()) {
System.out.println(rs1.getString("TempState"));
ExpectedState="s"+rs1.getString("TempState");
//ExpectedState.expState=(rs1.getString("TempState"));
System.out.println("ExpectedState:"+ExpectedState);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}finally{
try{
if(rs1!=null){
rs1.close();
rs1=null;
}
if(stmt!=null){
stmt.close();
stmt=null;
}
if (conn !=null){
conn.close();
conn=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
/*public void getExpectedState(String ExpectedState){
this.ExpectedState = ExpectedState;
System.out.println("ExpectedState:"+ExpectedState);*/??????????????????????
}
I want to use Java to pass the datavalue of expectedState from MYSQL database ,save it and pass to another file called State.java?
*********************************************************************
// State.java
package JDBC;
import JDBC.split.*;
public class State {
//private int startState;
private int expectedState;
public State( int theStateId, int theExpectedState)
super( );
this.expectedState = theExceptedState;
}
public class getExceptedState(){
return exceptedState;
} public static class setExceptedState(String theExceptedState private String expectedState)
{
this.exceptedState = theExceptedState;
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(exceptedState.getExceptedState);
}
}//TestMyssqlConnection.java***************************************************************************88888
package JDBC;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TestFSMMyssqlConnection {
//public static final Object MidState = null;//by eclipse on May 14
public static String ExpectedState;// change by me on May15
public void getExpectedState(String ExpectedState){
this.ExpectedState = ExpectedState;
System.out.println("ExpectedState:"+ExpectedState);
} public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs1 = null;
//Object MidState = null;//added by eclipse
//String MidState ;
String ExpectedState;
//ResultSet rs2=null; try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager
.getConnection("jdbc:mysql://localhost/myfsmdata?user=root&password=root");
stmt = conn.createStatement();
rs1 = stmt.executeQuery("select TempState from fsm2 where stateid=0");// using transitons replace *
//rs2 = stmt.executeQuery("select TempState from fsm2 where stateid=0");
while (rs1.next()) {
System.out.println(rs1.getString("TempState"));
ExpectedState="s"+rs1.getString("TempState");
//ExpectedState.expState=(rs1.getString("TempState"));
System.out.println("ExpectedState:"+ExpectedState);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}finally{
try{
if(rs1!=null){
rs1.close();
rs1=null;
}
if(stmt!=null){
stmt.close();
stmt=null;
}
if (conn !=null){
conn.close();
conn=null;
}
}catch(SQLException e){
e.printStackTrace();
}
}
}
/*public void getExpectedState(String ExpectedState){
this.ExpectedState = ExpectedState;
System.out.println("ExpectedState:"+ExpectedState);*/??????????????????????
}
liuyann老师,如何读取文件的某一data: from mysql pass its value to another file called State.java to ,谢谢帮助!如何读取文件的某一data:actualState?use State.java to 读取 actualState from split.java?
实际上,我在split.java已经得到expectedState的价值,
如何 递actuaeState 值从文件 split.java 输到另一个文件 State.java?Thanks!
or 引用 actuaeState 值 in 另一个文件 State.java
or 将actualState= s0 从 split.java 导出数据 to another File named State.java
I am not able to understand your requirement clearly. let's clarify.1. do you need save the data to another data file ?or2. do you need interaction between two processes / applications (split.java, state.jave)I supposed your selection is the 2nd. interaction between 2 applications, you must use some singal to control, you can use a shared data file, or a shared memory.
[align=center]==== 思想重于技巧 ====
[/align]
public class State {
private static String expectedState;
public State( String expectedState){
}
public class getExpectedState(){
return expectedState;// the first error
} public static class setExpectedState(static String expectedState)
{
this.expectedState = expectedState;
}
public static void main(String[] args) {
TestFSMMyssqlConnection fsm = new TestFSMMyssqlConnection();
State st= new State(); // the second error
st.setExpectedState(fsm.expectedState);// the last one
System.out.println(expectedState);
}
}