sqlserve 解决SQL Server 无法打开默认数据库问题 点击打开链接
最近写了一个j2ee的小作业,然后需要用到数据库~
于是乎,,每次连接数据库,找软件就很蛋疼~~~~
我用的是mysql5.5的数据库,然后驱动是mysql-connector-java-5.1.22-bin
接下来是数据库的连接代码(还有一些代码是sqlserver的数据库连接)
package com;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import com.mysql.jdbc.*;
public class SqlLog implements Serializable {
private Connection connection;
private PreparedStatement UserQuery;
private static String url = "jdbc:mysql://localhost:3306/Loguser"
private static String user = "root";
private static String password = "911018";
public SqlLog()
{
//String driverClassName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
//String url ="jdbc:sqlserver://127.0.0.1:1433;databaseName=Loguser";
String driverClassName = "com.mysql.jdbc.Driver";
try
{
Class.forName(driverClassName);
if (connection == null || connection.isClosed())
connection = DriverManager.getConnection( url, user,password);
}
catch (ClassNotFoundException ex)
{
ex.printStackTrace();
System.out.println("Oh,not");
}
catch(SQLException e)
{
e.printStackTrace();
System.out.println("Oh,not");
}
}
public void SqlShow()
{
try {
UserQuery = connection.prepareStatement("select * from myuser");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
ResultSet results = UserQuery.executeQuery();
while(results.next())
{
String myname = results.getString("name");
String mypassword = results.getString("pwd1");
int islog = results.getInt("islog");
System.out.println(myname + mypassword + " "+islog);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String Selectpwd(String name)
{
String pwd = null;
try {
UserQuery = connection.prepareStatement("select * from myuser where name = ?");
UserQuery.setString(1, name);
ResultSet result = UserQuery.executeQuery();
while (result.next())
pwd = result.getString("pwd1");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return pwd;
}
public void SetUserId(int id,String name)
{
try
{
UserQuery = connection.prepareStatement("UPDATE myuser set islog = ? where name = ?");
UserQuery.setInt(1,id);
UserQuery.setString(2, name);
UserQuery.executeUpdate();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
public Vector selectLogname()
{
Vector v = new Vector();
try
{
UserQuery =connection.prepareStatement("SELECT * FROM myuser where islog = 1");
ResultSet result = UserQuery.executeQuery();
while(result.next())
{
Juser user = new Juser();
user.setName(result.getString("name"));
user.setPwd(result.getString("pwd1"));
v.add(user);
}
}
catch(SQLException e)
{
e.printStackTrace();
return null;
}
return v;
}
public int checkName(String name)
{
String id=null;
try{
UserQuery = connection.prepareStatement("select * from myuser where name = ?");
UserQuery.setString(1, name);
ResultSet result = UserQuery.executeQuery();
while(result.next()){
id = result.getString("pwd1");
break;
}
}
catch(SQLException e)
{
e.printStackTrace();
return 0;
}
if(name != null)
return 1;
return 0;
}
public static void main (String[] args)
// TODO Auto-generated method stub
{
SqlLog mysql = new SqlLog();
if(mysql != null){
mysql.SqlShow();
System.out.println(mysql.Selectpwd("zwy"));}
}
}
接下来是数据库mysql数据库的备份
因为是windows所以需要到
1. 走到mysql\bin 目录下
2. mysqldump -u root -proot bv1to1 > bv1to1.sql
ok 这样就可以成功备份了~
mysql hiberate 提示的sql语句可以查询但是查询不出结果
修改方式
<property name="connection.url">
jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=UTF-8
</property>
mysql 设置中文显示问题点
最近碰见了一个sqlserver安装的时候,老是TCP连接不了,数据库也没有问题,最后找到原因,原来是数据库配置的时候不是默认的1433端口号,感谢查看sqlserver端口号的这位兄弟。
以下是sqlserver在命令行下的查看端口号的语句
exec sys.sp_readerrorlog 0, 1, 'listening'
mysql 中关于 left join的一个博客主要是关于left join on a条件 and b 条件 会有什么样的结果。如果left join on a条件 and b 条件 where B表的id is NULL 会有什么后果。点击打开链接