数据库查询?

发布网友 发布时间:2022-04-24 03:20

我来回答

1个回答

懂视网 时间:2022-04-10 02:26

package com.JDBC.proc; 2 3 import java.sql.*; 4 5 public class PrepareStatement { 6 private static final String DBDRIVER = "com.mysql.jdbc.Driver"; 7 private static final String DBURL = "jdbc:mysql://localhost:3306/mldn"; 8 private static final String DBUSER = "root"; 9 private static final String DBPASS = "root"; 10 public static void main(String[] args) throws Exception{ 11 12 Connection conn=null; 13 PreparedStatement psmt=null; 14 ResultSet rs=null; 15 Class.forName(DBDRIVER); 16 17 conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS); 18 String sql="select empno,ename " + "from emp " + "where empno=?"; 19 psmt=conn.prepareStatement(sql); 20 psmt.setInt(1, 123); 21 22 rs=psmt.executeQuery(); 23 while(rs.next()){ 24 System.out.println(rs.getInt(1)+"---"+rs.getString(2)); 25 } 26 rs.close(); 27 psmt.close(); 28 conn.close(); 29 30 } 31 }

 

数据库查询(二)

标签:jdb   connect   row   bpa   final   class   ext   use   nbsp   

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com