就像下面这个 Hello World 一样。
mysql>DELIMITER //
mysql>CREATE PROCEDURE HelloWorld()
->BEGIN
->SELECT 'Hello World'
->END//
Query OK, 0 rows affected (0.00 sec)
mysql>call HelloWorld()
->//
+-------------+
| Hello World |
+-------------+
| Hello World |
+-------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
要使用mysql的jar包,数据库名为test,表名shop,列名shopNamepackage com.yunix
import java.sql.Connection
import java.sql.DriverManager
import java.sql.ResultSet
import java.sql.SQLException
import java.sql.Statement
public class Test {
public static void main(String []args){
Connection con = getAccessCon()
try {
Statement st = con.createStatement()
ResultSet rs = st.executeQuery("select * from shop")
while(rs.next()){
System.out.println(rs.getString("shopName"))
}
rs.close()
st.close()
con.close()
} catch (SQLException e) {
e.printStackTrace()
}
}
public static Connection getAccessCon(){
Connection con = null
try{
Class.forName("com.mysql.jdbc.Driver").newInstance()
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user=root&password=root")
}catch(Exception e){
e.printStackTrace()
}
return con
}
}
1、只能用 SELECT.就像下面这个 Hello World 一样,mysql>DELIMITER //,mysql>CREATE PROCEDURE HelloWorld, BEGIN,SELECT 'Hello World',END/,Query OK, 0 rows affected (0.00 sec),mysql>call HelloWorld,Hello World ,row in set 0.00 sec,Query OK, 0 rows affected只有SELECT了。
2、mysql没有sqlserver里面控制台的概念,因为mysql全部都是控制台
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)