当前位置:首页 > 代码 > 正文

资料库源代码(源码库官网)

admin 发布:2022-12-19 21:33 147


本篇文章给大家谈谈资料库源代码,以及源码库官网对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

如何查看数据库中表的源代码

右键单击该数据库,任务,生成脚本,一直选下一步,然后遇见勾选的都全选,最后完成就行了

我用的是SQL2005

网上下载了软件的源代码和数据库,怎么运行它呢

先看一下业务层中的BaseDao(连接数据库的类),看一下连接数据库的用户名和密码是不是正确,看看驱动包是否导入,就是sqljdbc的文件,如果没导入,把它粘贴到WebRoot下的WEB-INF下的lib目录中,我给你一段连接SQLServer2005的一段代码,你参考一下吧!

package dao.impl;

import java.sql.*;

public class BaseDao {

private static final String DRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriver";

private static final String URL="jdbc:sqlserver://localhost:1433;databasename=epet";//epet是数据源的名称

private static final String DBUSER="sa";//数据库用户名

private static final String DBPASS="123";";//数据库密码

private Connection conn=null;

/**

* 获取连接

* @return

*/

public Connection getConn(){

try {

Class.forName(DRIVER);

conn=DriverManager.getConnection(URL,DBUSER,DBPASS);

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return conn;

}

/**

* 释放资源

* @param conn

* @param pstmt

* @param rs

*/

public void closeAll(Connection conn,PreparedStatement pstmt,ResultSet rs){

try {

if(rs!=null){

rs.close();

}

if(pstmt!=null){

pstmt.close();

}

if(conn!=null){

conn.close();

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

PHP 怎么显示数据库中的数据 求源代码

读数据库,以表格输出的示例代码:

?php

header('Content-type:text/html;charset=utf-8');

$db = new mysqli('localhost','root','root','books');

$rows = $db-query('SELECT * FROM customers');

echo 'table border="1"trtd姓名/tdtd年龄/td/tr';

while($row = $rows-fetch_assoc()){

echo 'trtd'.$row['name'].'/td';

echo 'td'.$row['address'].'/td/tr';

}

?

你有一个简单的数据库的源代码吗?最好用Java实现的...

class ConnectionProvider{

private static String JDBC_DRIVER;

private static String DB_URL;

private static String DB_USER;

private static String DB_PASSWORD;

public ConnectionProvider()

{

JDBC_DRIVER = "com.mysql.jdbc.Driver"

DB_URL = "jdbc:mysql://localhost:3306/u-disk";

DB_USER = "root";

DB_PASSWORD = "root"

};

public Connection getConnection()

{

try {

Class.forName(JDBC_DRIVER);

} catch (Exception e) {

System.out.println("驱动文件路径有误!");

}

}

Connection con = null;

try {

con = DriverManager.getConnection(DB_URL, DB_USER,

DB_PASSWORD);

} catch (SQLException e) {

System.out.println("数据库连接建立异常!\n@shy2850@" + e.getMessage() +

e.getCause());

}

System.out.println("得到连接:Connection " + ConnectionPool.connections.size() + 1);

return new ConnectionImpl(con);

}

}

可以使用这个包装的数据库连接数据源在DAO工具类中使用:

package com.jdbc;

import java.sql.*;

/**课题:封装数据库的增删改查的工具类的实现。

*

* 假设相关数据库的表结构如下:

* 表名:user

* 列名及属性:id(int 自增),name(varchar(20)),tele(char(12)),birthday(date)

* @author shy2850

*/

public class UserDAO {

Connection conn;

public UserDAO(Connection conn) {

this.conn = conn;

}

public int save(User user) throws SQLException {

String sql = "insert into user values(0,?,?,?)";

PreparedStatement pstmt = conn.prepareStatement(sql);

pstmt.setString(1, user.getName());

pstmt.setString(2, user.getTele());

pstmt.setDate(3, user.getBirthday());

int n = pstmt.executeUpdate();

pstmt.close();

return n;

}

public int delete(User user) throws SQLException{

String sql = "delete from user where id = "+user.getId();

Statement stmt = conn.createStatement();

int n = stmt.executeUpdate(sql);

stmt.close();

return n;

}

public int update(User user) throws SQLException{

String sql = "update user set name=?, tele=?, birthday=? where id = "+user.getId();

PreparedStatement pstmt = conn.prepareStatement(sql);

pstmt.setString(2, user.getName());

pstmt.setString(3, user.getTele());

pstmt.setDate(4, user.getBirthday());

int n = pstmt.executeUpdate(sql);

pstmt.close();

return n;

}

public User getUser(Integer id) throws SQLException{

String sql = "select * from user where id = " + id;

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery(sql);

User user = getUserFromResultSet(rs);

rs.close();

stmt.close();

return user;

}

static User getUserFromResultSet(ResultSet rs) throws SQLException{

Integer id = rs.getInt("id");

String name= rs.getString("name");

String tele= rs.getString("tele");

Date birthday = rs.getDate("birthday");

return new User(id, name, tele, birthday);

}

}

/**

* 构建数据库表的java类映射

*/

class User{

private Integer id;

private String name;

private String tele;

private Date birthday;

public User() {

}

public User(Integer id, String name, String tele, Date birthday) {

super();

this.id = id;

this.name = name;

this.tele = tele;

this.birthday = birthday;

}

public Integer getId() {

return id;

}

public void setId(Integer id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getTele() {

return tele;

}

public void setTele(String tele) {

this.tele = tele;

}

public Date getBirthday() {

return birthday;

}

public void setBirthday(Date birthday) {

this.birthday = birthday;

}

}

PHP源代码连接数据库

数据库有很多种类:mysql,oracle,mssql,db2等等。PHP操作数据库的时候,要保证该类型数据库的扩展已开启。这里连接的数据库以mysql为例:

?php

//数据库服务器地址

$host="localhost"; 

//连接数据库用户名

$uname="root"; 

//连接数据库密码

$upass=""; 

//连接数据库

$conn=mysql_connect($host, $uname,$upass);

//判断连接

if(!$conn){

    die("连接数据库失败!").mysql_errno();    

}

//连接成功,其他操作省略

?

关于资料库源代码和源码库官网的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/25306.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载