Code that was written under eclipse:
1 import LRAPI.LR;2 import java.sql.Connection;3 import Java.sql.DriverManager;4 import java.sql.PreparedStatement;5 import Java.sql.ResultSet;6 7 Public classActions {8 //define the user name, password, URL of the connection9String username ="Root";TenString Password ="123456"; OneString URL ="Jdbc:mysql://127.0.0.1:3306/oa"; AString sql ="SELECT * from itcast_user where id = 2"; - Public intinit () throws Throwable { - //1 registering MySQL driver theClass.forName ("Com.mysql.jdbc.Driver"); - return 0; -}//End of Init - + Public intaction () throws Throwable { - //2 connecting MySQL, importing java.sql.Connection +Connection conn =drivermanager.getconnection (Url,username,password); A //3 Get the SQL Executor class, import java.sql.preparedstatement atPreparedStatement PS =conn.preparestatement (SQL); - //4 Execute SQL statement, get to execution result object ResultSet (import) -ResultSetSet=ps.executequery (); - //Print the acquired data - while(Set. Next ()) { -String name =Set. getString ("name"); inSystem. out. println ("name"+name); - } to //turn off Resultset,preparedstatement,connection . + Set. Close (); - ps.close (); the conn.close (); * return 0; $}//End of ActionPanax Notoginseng - Public intEnd () throws Throwable { the + return 0; A}//End of End the + /* - //program to execute the entrance, in LR do not write $ Public static void Main (string[] args) throws throwable{ $ actions = new actions (); - actions.init (); - actions.action (); the actions.end (); - }*/Wuyi}
Copy to LR and check for syntax errors.
Set LR Run settings: Run-time Settings
Everything is ready, next look to see if the data is queried, as shown in the data return proof script runs through:
The script in this article is intended for debugging purposes only, as there are areas to be optimized, such as adding parameterization, transactions, checkpoints, and so on.
LR Interface Test---Java vuser before JDBC debugging