Eclipse里SQL Server语句问题
packagecom.jzbr.ST57;importjava.sql.*;//导入SQL包导入java.sql.*;publicclassSelect{publicst...
package com.jzbr.ST57;
import java.sql.*;//导入SQL包导入 java.sql.*;
public class Select {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=bbs","sa","sa2005");
// 3.创建查询通道
Statement stmt = conn.createStatement();
//4.执行sql语句得到结果
//ResultSet rs=stmt.executeQuery("select boardid ,boardName,parentId from tbl_board");
ResultSet rs = stmt.executeQuery("SELECT * FROM TBL_BOARD WHERE boardName = 'Jack'");
这里的名字Jack ,我想通过键盘输入,各位大神,不知能否实现,小弟新手,求受教!
//5.循环输出结果集中的内容
while(rs.next()){//判断是否为空
//在jdbc中结果集的下标从1开始
System.out.print(rs.getInt(1)+"\t");
System.out.print(rs.getString(2)+"\t");
System.out.println(rs.getInt(3));
}
rs.close();
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
} 展开
import java.sql.*;//导入SQL包导入 java.sql.*;
public class Select {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=bbs","sa","sa2005");
// 3.创建查询通道
Statement stmt = conn.createStatement();
//4.执行sql语句得到结果
//ResultSet rs=stmt.executeQuery("select boardid ,boardName,parentId from tbl_board");
ResultSet rs = stmt.executeQuery("SELECT * FROM TBL_BOARD WHERE boardName = 'Jack'");
这里的名字Jack ,我想通过键盘输入,各位大神,不知能否实现,小弟新手,求受教!
//5.循环输出结果集中的内容
while(rs.next()){//判断是否为空
//在jdbc中结果集的下标从1开始
System.out.print(rs.getInt(1)+"\t");
System.out.print(rs.getString(2)+"\t");
System.out.println(rs.getInt(3));
}
rs.close();
stmt.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |